summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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