From 6d722bb19f33c82f5b65923f09be669a5bb5e480 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 9 Mar 2023 18:07:16 +0100 Subject: [PATCH] feedback when there are one error in sanitization form --- ereuse_devicehub/forms.py | 6 ++++++ ereuse_devicehub/inventory/forms.py | 12 +++++++++++- ereuse_devicehub/views.py | 5 ++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/ereuse_devicehub/forms.py b/ereuse_devicehub/forms.py index 68485f33..4980b41e 100644 --- a/ereuse_devicehub/forms.py +++ b/ereuse_devicehub/forms.py @@ -141,6 +141,12 @@ class SanitizationEntityForm(FlaskForm): if not is_valid: return False + extensions = ["jpg", "jpeg", "png", "gif", "svg"] + if self.logo.data.lower().split(".")[-1] not in extensions: + txt = "Error in Url field - accepted only .PNG, .JPG and .GIF. extensions" + self.logo.errors = [txt] + return False + return True def save(self, commit=True): diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index a4504f17..dff4e87e 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -1561,7 +1561,17 @@ class CustomerDetailsForm(FlaskForm): def validate(self, extra_validators=None): is_valid = super().validate(extra_validators) - return is_valid + + if not is_valid: + return is_valid + + extensions = ["jpg", "jpeg", "png", "gif", "svg"] + if self.logo.data.lower().split(".")[-1] not in extensions: + txt = "Error in Url field - accepted only .PNG, .JPG and .GIF. extensions" + self.logo.errors = [txt] + return False + + return True def save(self, commit=True): self.populate_obj(self._obj) diff --git a/ereuse_devicehub/views.py b/ereuse_devicehub/views.py index 915a4dc4..65cb4d3a 100644 --- a/ereuse_devicehub/views.py +++ b/ereuse_devicehub/views.py @@ -143,8 +143,11 @@ class SanitizationEntityView(View): messages.success('Sanitization data updated successfully!') else: messages.error('Error modifying Sanitization data!') + if form.errors: + for k in form.errors.keys(): + txt = "{}: {}".format(k, form.errors[k]) + messages.error(txt) - # db.session.commit() return flask.redirect(flask.url_for('core.user-profile'))