Combine data properties and remove unused import

This commit is contained in:
leigh-mil 2019-02-27 13:32:37 -05:00
parent a6296e78df
commit 3b5b809947
2 changed files with 7 additions and 13 deletions

View File

@ -5,6 +5,8 @@ from atst.utils.flash import formatted_flash as flash
class ValidatedForm(FlaskForm):
EMPTY_LIST_FIELD = ["", None]
def perform_extra_validation(self, *args, **kwargs):
"""Performs any applicable extra validation. Must
return True if the form is valid or False otherwise."""
@ -13,6 +15,11 @@ class ValidatedForm(FlaskForm):
@property
def data(self):
_data = super().data
for field in _data:
if _data[field].__class__.__name__ == "list":
_data[field] = [
el for el in _data[field] if el not in self.EMPTY_LIST_FIELD
]
_data.pop("csrf_token", None)
return _data
@ -24,20 +31,8 @@ class ValidatedForm(FlaskForm):
class CacheableForm(ValidatedForm):
EMPTY_LIST_FIELD = ["", None]
def __init__(self, formdata=None, **kwargs):
formdata = formdata or {}
cached_data = current_app.form_cache.from_request(http_request)
cached_data.update(formdata)
super().__init__(cached_data, **kwargs)
@property
def data(self):
_data = super(FlaskForm, self).data
for field in _data:
if _data[field].__class__.__name__ == "list":
_data[field] = [
el for el in _data[field] if el not in self.EMPTY_LIST_FIELD
]
return _data

View File

@ -1,5 +1,4 @@
from flask_wtf.file import FileAllowed
from flask_wtf import FlaskForm
from wtforms.fields.html5 import DateField
from wtforms.fields import StringField, TextAreaField, FileField, FieldList