summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJavier Hernandez <jhernandez@soleta.eu>2024-02-02 12:30:47 +0100
committerOpenGnSys Support Team <soporte-og@soleta.eu>2024-02-02 12:48:28 +0100
commit6a134b63372311706f174516a45ad2af8c7ff225 (patch)
tree1a94436177fb5c96a461ff2b783a0797435e69d0
parenta41ad5eec6cefe540cbb5c4a5454c0c4ae24bf1c (diff)
Make list_images show only selected images
Make list images command show only information of the images the user has selected in the sidebar. Improve readability of the information. Show size and data size attributes rounded Warn the user if no images have been selected in sidebar
-rw-r--r--ogcp/templates/actions/list_images.html19
-rw-r--r--ogcp/views.py33
2 files changed, 28 insertions, 24 deletions
diff --git a/ogcp/templates/actions/list_images.html b/ogcp/templates/actions/list_images.html
index e2f5633..694036f 100644
--- a/ogcp/templates/actions/list_images.html
+++ b/ogcp/templates/actions/list_images.html
@@ -6,15 +6,11 @@
{% block content %}
<h1 class="m-5">{{_('List images')}}</h1>
-{% for r in responses %}
- {% set server = r['server']['name']%}
- {% set repos = r['repos'] %}
- {% for repo in repos.values() %}
- {% set repo_name = repo['name'] %}
- {% set images = repo['images'] %}
- {% if images %}
- {{ repo_name }} ({{ server }})
- <table class="table table-hover">
+{% for server in servers %}
+ <h3 class="mx-5">Server: {{server['name']}}</h3>
+ {% for repo, images in server['repos'] %}
+ <h4 class="mx-5">Repo: {{repo}}</h4>
+ <table class="table table-hover mx-5">
<thead class="thead-light">
<tr>
<th>Name</th>
@@ -27,14 +23,13 @@
{% for img in images %}
<tr>
<th>{{img['name']}}</th>
- <td>{{img['size'] / 1024 ** 2}}</td>
- <td>{{img['datasize'] / 1024 ** 2}}</td>
+ <td>{{(img['size'] / 1024 ** 2) |round(2, 'floor')}}</td>
+ <td>{{(img['datasize'] / 1024 ** 2) |round(2, 'floor')}}</td>
<td>{{img['modified']}}</td>
</tr>
{% endfor %}
</tbody>
</table>
- {% endif %}
{% endfor %}
{% endfor %}
diff --git a/ogcp/views.py b/ogcp/views.py
index c2be721..cdb1582 100644
--- a/ogcp/views.py
+++ b/ogcp/views.py
@@ -2516,25 +2516,34 @@ def user_delete_get():
def action_image_list():
params = request.args.to_dict()
ids = parse_elements(params)
+ ids = [int(id) for id in ids if id.isdigit()]
+ if not ids:
+ flash(_('Please, select an image'), category='error')
+ return redirect(url_for('images'))
server = get_server_from_ip_port(params['image-server'])
- r = server.get('/images')
- if not r:
- return ogserver_down('images')
- if r.status_code != requests.codes.ok:
- return ogserver_error('images')
- tmp = r.json()['images']
- images = []
- for img in tmp:
- if img['id'] in ids:
- images.append(img)
try:
- images = get_images_grouped_by_repos()
+ responses = get_images_grouped_by_repos()
+ servers = []
+ for server in responses:
+ repos = []
+ for unused, repo in server['repos'].items():
+ images=[]
+ for img in repo['images']:
+ if int(img['id']) in ids:
+ images.append(img)
+ if images:
+ repos.append((repo['name'], images))
+ if repos:
+ s={}
+ s['name'] = server['server'].name
+ s['repos'] = repos
+ servers.append(s)
except ServerError:
return ogserver_down('images')
except ServerErrorCode:
return ogserver_error('images')
return render_template('actions/list_images.html',
- responses=images)
+ servers=servers, responses=responses)
@app.route('/user/delete', methods=['POST'])
@login_required