Move removing empty items in a list field to CacheableForm
This commit is contained in:
parent
7b41b8e94c
commit
e00e24f083
@ -15,8 +15,6 @@ class ApplicationForm(FlaskForm):
|
|||||||
|
|
||||||
|
|
||||||
class NewApplicationForm(ApplicationForm):
|
class NewApplicationForm(ApplicationForm):
|
||||||
EMPTY_ENVIRONMENT_NAMES = ["", None]
|
|
||||||
|
|
||||||
environment_names = FieldList(
|
environment_names = FieldList(
|
||||||
StringField(label=translate("forms.application.environment_names_label")),
|
StringField(label=translate("forms.application.environment_names_label")),
|
||||||
validators=[
|
validators=[
|
||||||
@ -32,13 +30,3 @@ class NewApplicationForm(ApplicationForm):
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
|
||||||
def data(self):
|
|
||||||
_data = super(FlaskForm, self).data
|
|
||||||
_data["environment_names"] = [
|
|
||||||
n
|
|
||||||
for n in _data["environment_names"]
|
|
||||||
if n not in self.EMPTY_ENVIRONMENT_NAMES
|
|
||||||
]
|
|
||||||
return _data
|
|
||||||
|
@ -24,8 +24,18 @@ class ValidatedForm(FlaskForm):
|
|||||||
|
|
||||||
|
|
||||||
class CacheableForm(ValidatedForm):
|
class CacheableForm(ValidatedForm):
|
||||||
|
EMPTY_LIST_FIELD = ["", None]
|
||||||
|
|
||||||
def __init__(self, formdata=None, **kwargs):
|
def __init__(self, formdata=None, **kwargs):
|
||||||
formdata = formdata or {}
|
formdata = formdata or {}
|
||||||
cached_data = current_app.form_cache.from_request(http_request)
|
cached_data = current_app.form_cache.from_request(http_request)
|
||||||
cached_data.update(formdata)
|
cached_data.update(formdata)
|
||||||
super().__init__(cached_data, **kwargs)
|
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
|
||||||
|
@ -11,8 +11,6 @@ from atst.utils.localization import translate
|
|||||||
|
|
||||||
|
|
||||||
class KOReviewForm(CacheableForm):
|
class KOReviewForm(CacheableForm):
|
||||||
EMPTY_LOA = ["", None]
|
|
||||||
|
|
||||||
start_date = DateField(
|
start_date = DateField(
|
||||||
translate("forms.ko_review.start_date_label"), format="%m/%d/%Y"
|
translate("forms.ko_review.start_date_label"), format="%m/%d/%Y"
|
||||||
)
|
)
|
||||||
@ -36,9 +34,3 @@ class KOReviewForm(CacheableForm):
|
|||||||
description=translate("forms.ko_review.custom_clauses_description"),
|
description=translate("forms.ko_review.custom_clauses_description"),
|
||||||
validators=[Optional()],
|
validators=[Optional()],
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
|
||||||
def data(self):
|
|
||||||
_data = super(FlaskForm, self).data
|
|
||||||
_data["loas"] = [n for n in _data["loas"] if n not in self.EMPTY_LOA]
|
|
||||||
return _data
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user