From 083caf00c61f9273522bb19a0cd89b83606808ec Mon Sep 17 00:00:00 2001 From: Javier Sánchez Parra Date: Tue, 30 Aug 2022 17:04:25 +0200 Subject: Adapt Delete image to work with several ogServers This commit makes Delete image view to use ogServer field from imagesForm to send the deletion request to the correct ogServer. --- ogcp/forms/action_forms.py | 1 + ogcp/views.py | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'ogcp') diff --git a/ogcp/forms/action_forms.py b/ogcp/forms/action_forms.py index a7bb5b4..dcf4965 100644 --- a/ogcp/forms/action_forms.py +++ b/ogcp/forms/action_forms.py @@ -18,6 +18,7 @@ from flask_babel import _ class GenericForm(FlaskForm): ips = HiddenField() ids = HiddenField() + server = HiddenField() submit = SubmitField(label=_l('Submit')) diff --git a/ogcp/views.py b/ogcp/views.py index c2a40b8..0511d3c 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -1661,19 +1661,24 @@ def action_image_delete(): return redirect(url_for('images')) id = ids.pop() payload = {'image': id} - r = g.server.post('/image/delete', payload) + server = get_server_from_ip_port(form.server.data) + r = 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')) else: - images = [(name, imgid) for name, imgid in request.args.to_dict().items() if name != "csrf_token"] + params = request.args.to_dict() + images = [(name, imgid) for name, imgid in params.items() + if name != 'csrf_token' and name != 'image-server'] if not validate_elements(images, max_len=1): return redirect(url_for('images')) image_name, image_id = images[0] + server = get_server_from_ip_port(params['image-server']) responses = multi_request('get', '/images') form.ids.data = image_id + form.server.data = params['image-server'] if not validate_elements(images, max_len=1): flash(_('Please select one image to delete'), category='error') return redirect(url_for('images')) -- cgit v1.2.3-18-g5258