diff options
Diffstat (limited to 'ogcp')
-rw-r--r-- | ogcp/templates/actions/delete_image.html | 3 | ||||
-rw-r--r-- | ogcp/views.py | 37 |
2 files changed, 22 insertions, 18 deletions
diff --git a/ogcp/templates/actions/delete_image.html b/ogcp/templates/actions/delete_image.html index 3eeab42..69acc79 100644 --- a/ogcp/templates/actions/delete_image.html +++ b/ogcp/templates/actions/delete_image.html @@ -8,8 +8,9 @@ {{ args }} +{% set img_count = image_ids | length %} <h2 class="mx-5 subhead-heading"> - {{ _('Delete image %(image_name)s', image_name=image_name) }} + {{ _('Delete %(img_count)d image(s)', img_count=img_count) }} </h2> {{ wtf.quick_form(form, diff --git a/ogcp/views.py b/ogcp/views.py index 6d729f3..3725899 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -3582,26 +3582,29 @@ def action_image_delete(): form = GenericForm(request.form) if request.method == 'POST': ids = form.ids.data.split(' ') - if not validate_elements(ids, max_len=1): + if not validate_elements(ids): return redirect(url_for('images')) - id = ids.pop() - payload = {'image': id} + server = get_server_from_ip_port(form.server.data) - r = server.post('/image/delete', payload) - if not r: - return ogserver_down('images') - if r.status_code != requests.codes.ok: - flash(_('OgServer replied with a non ok status code'), category='error') - else: - flash(_('Image deletion request sent successfully'), category='info') + + for id in ids: + payload = {'image': id} + r = server.post('/image/delete', payload) + if not r: + return ogserver_down('images') + if r.status_code != requests.codes.ok: + return ogserver_error('images') + + flash(_('Image deletion request sent successfully'), category='info') return redirect(url_for('images')) else: params = request.args.to_dict() - images = [(name, imgid) for name, imgid in params.items() + image_ids = [imgid for name, imgid in params.items() if name != 'csrf_token' and name != 'image-server'] - if not validate_elements(images, max_len=1): + + if not validate_elements(image_ids): return redirect(url_for('images')) - image_name, image_id = images[0] + server = get_server_from_ip_port(params['image-server']) try: responses = get_images_grouped_by_repos() @@ -3609,12 +3612,12 @@ def action_image_delete(): return ogserver_down('images') except ServerErrorCode: return ogserver_error('images') - form.ids.data = image_id + + form.ids.data = ' '.join(image_ids) form.server.data = params['image-server'] - if not validate_elements(images, max_len=1): - return redirect(url_for('images')) + return render_template('actions/delete_image.html', form=form, - image_name=image_name.split('_', 1)[0], image_id=image_id, + image_ids=image_ids, responses=responses) @app.route('/action/image/config', methods=['GET', 'POST']) |