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: if not is_valid:
return False 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 return True
def save(self, commit=True): def save(self, commit=True):

View File

@ -1561,7 +1561,17 @@ class CustomerDetailsForm(FlaskForm):
def validate(self, extra_validators=None): def validate(self, extra_validators=None):
is_valid = super().validate(extra_validators) 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): def save(self, commit=True):
self.populate_obj(self._obj) self.populate_obj(self._obj)

View File

@ -143,8 +143,11 @@ class SanitizationEntityView(View):
messages.success('Sanitization data updated successfully!') messages.success('Sanitization data updated successfully!')
else: else:
messages.error('Error modifying Sanitization data!') 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')) return flask.redirect(flask.url_for('core.user-profile'))