summaryrefslogtreecommitdiffstats
path: root/ogcp/views.py
diff options
context:
space:
mode:
authorJose M. Guisado <jguisado@soleta.eu>2022-01-27 16:51:35 +0100
committerJose M. Guisado <jguisado@soleta.eu>2022-01-27 16:51:35 +0100
commit31b1e920772ce6dd56f3f56b5a882c2f71333c13 (patch)
treeacd9cab08f7a7fb5691828be7394d3fbf0c76855 /ogcp/views.py
parentb566528012aabfc435f82525d84471ab7bbcff74 (diff)
Add confirmation page when deleting image
User can confirm when deleting an image by double checking the information displayed on this page. Adds a new optional field in GenericForm: 'ids'. Used when dealing with ids instead of ips.
Diffstat (limited to 'ogcp/views.py')
-rw-r--r--ogcp/views.py36
1 files changed, 25 insertions, 11 deletions
diff --git a/ogcp/views.py b/ogcp/views.py
index 3c587d2..a5e9573 100644
--- a/ogcp/views.py
+++ b/ogcp/views.py
@@ -953,21 +953,35 @@ def action_image_info():
return render_template('actions/image_details.html', form=form)
-@app.route('/action/image/delete', methods=['POST'])
+@app.route('/action/image/delete', methods=['GET', 'POST'])
@login_required
def action_image_delete():
- ids = parse_elements(request.form.to_dict())
- if not validate_elements(ids, max_len=1):
+ form = GenericForm(request.form)
+ if request.method == 'POST':
+ ids = form.ids.data.split(' ')
+ if not validate_elements(ids, max_len=1):
+ return redirect(url_for('images'))
+ id = ids.pop()
+ payload = {'image': id}
+ r = g.server.post('/image/delete', payload)
+ 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')
return redirect(url_for('images'))
-
- id = ids.pop()
- payload = {'image': id}
- r = g.server.post('/image/delete', payload)
- if r.status_code != requests.codes.ok:
- flash(_('OgServer replied with a non ok status code'), category='error')
else:
- flash(_('Delete client request processed successfully'), category='info')
- return redirect(url_for('images'))
+ images = [(name, imgid) for name, imgid in request.args.to_dict().items() if name != "csrf_token"]
+ if not validate_elements(images, max_len=1):
+ return redirect(url_for('images'))
+ image_name, image_id = images[0]
+ r = g.server.get('/images')
+ form.ids.data = image_id
+ if not validate_elements(images, max_len=1):
+ flash(_('Please select one image to delete'), category='error')
+ 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,
+ images=r.json()['images'])
@app.route('/action/log', methods=['GET'])
@login_required