summaryrefslogtreecommitdiffstats
path: root/ogcp/views.py
diff options
context:
space:
mode:
authorAlejandro Sirgo Rica <asirgo@soleta.eu>2024-08-06 12:33:22 +0200
committerAlejandro Sirgo Rica <asirgo@soleta.eu>2024-08-06 12:40:33 +0200
commitace0c5bb46ee78b0fe6533b5d50a2dd8c04198a4 (patch)
tree696ee9593d1ba6f7d1cd4b164fc0c178cf042566 /ogcp/views.py
parent4c1a86249b295368b7a933a50e36beaad5926c55 (diff)
views: enable multi-image deletion
Allow the deletion of multiple images in image/delete.
Diffstat (limited to 'ogcp/views.py')
-rw-r--r--ogcp/views.py37
1 files changed, 20 insertions, 17 deletions
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'])