feedback when there are one error in sanitization form

This commit is contained in:
Cayo Puigdefabregas 2023-03-09 18:07:16 +01:00
parent 93d6502a66
commit 6d722bb19f
3 changed files with 21 additions and 2 deletions

View File

@ -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):

View File

@ -1561,8 +1561,18 @@ class CustomerDetailsForm(FlaskForm):
def validate(self, extra_validators=None):
is_valid = super().validate(extra_validators)
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)
self._obj.logo = URL(self._obj.logo)

View File

@ -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'))