Move filter into a function

This commit is contained in:
leigh-mil 2019-03-12 10:40:46 -04:00
parent 21a0168d7e
commit 9277e5e4d0

View File

@ -27,6 +27,10 @@ from .data import (
from atst.utils.localization import translate from atst.utils.localization import translate
def remove_empty_string(value):
return value or None
class AppInfoWithExistingPortfolioForm(BaseForm): class AppInfoWithExistingPortfolioForm(BaseForm):
scope = TextAreaField( scope = TextAreaField(
translate("forms.task_order.scope_label"), translate("forms.task_order.scope_label"),
@ -54,28 +58,28 @@ class AppInfoWithExistingPortfolioForm(BaseForm):
description=translate("forms.task_order.complexity.description"), description=translate("forms.task_order.complexity.description"),
choices=APPLICATION_COMPLEXITY, choices=APPLICATION_COMPLEXITY,
default=None, default=None,
filters=[lambda x: x or None], filters=[remove_empty_string],
widget=ListWidget(prefix_label=False), widget=ListWidget(prefix_label=False),
option_widget=CheckboxInput(), option_widget=CheckboxInput(),
) )
complexity_other = StringField( complexity_other = StringField(
translate("forms.task_order.complexity_other_label"), translate("forms.task_order.complexity_other_label"),
default=None, default=None,
filters=[lambda x: x or None], filters=[remove_empty_string],
) )
dev_team = SelectMultipleField( dev_team = SelectMultipleField(
translate("forms.task_order.dev_team.label"), translate("forms.task_order.dev_team.label"),
description=translate("forms.task_order.dev_team.description"), description=translate("forms.task_order.dev_team.description"),
choices=DEV_TEAM, choices=DEV_TEAM,
default=None, default=None,
filters=[lambda x: x or None], filters=[remove_empty_string],
widget=ListWidget(prefix_label=False), widget=ListWidget(prefix_label=False),
option_widget=CheckboxInput(), option_widget=CheckboxInput(),
) )
dev_team_other = StringField( dev_team_other = StringField(
translate("forms.task_order.dev_team_other_label"), translate("forms.task_order.dev_team_other_label"),
default=None, default=None,
filters=[lambda x: x or None], filters=[remove_empty_string],
) )
team_experience = RadioField( team_experience = RadioField(
translate("forms.task_order.team_experience.label"), translate("forms.task_order.team_experience.label"),
@ -90,7 +94,7 @@ class AppInfoForm(AppInfoWithExistingPortfolioForm):
portfolio_name = StringField( portfolio_name = StringField(
translate("forms.task_order.portfolio_name_label"), translate("forms.task_order.portfolio_name_label"),
description=translate("forms.task_order.portfolio_name_description"), description=translate("forms.task_order.portfolio_name_description"),
filters=[lambda x: x or None], filters=[remove_empty_string],
validators=[ validators=[
Required(), Required(),
Length( Length(
@ -104,7 +108,7 @@ class AppInfoForm(AppInfoWithExistingPortfolioForm):
translate("forms.task_order.defense_component_label"), translate("forms.task_order.defense_component_label"),
choices=SERVICE_BRANCHES, choices=SERVICE_BRANCHES,
default="", default="",
filters=[lambda x: x or None], filters=[remove_empty_string],
) )
@ -146,36 +150,36 @@ class FundingForm(BaseForm):
class UnclassifiedFundingForm(FundingForm): class UnclassifiedFundingForm(FundingForm):
clin_02 = StringField( clin_02 = StringField(
translate("forms.task_order.unclassified_clin_02_label"), translate("forms.task_order.unclassified_clin_02_label"),
filters=[lambda x: x or None], filters=[remove_empty_string],
) )
clin_04 = StringField( clin_04 = StringField(
translate("forms.task_order.unclassified_clin_04_label"), translate("forms.task_order.unclassified_clin_04_label"),
filters=[lambda x: x or None], filters=[remove_empty_string],
) )
class OversightForm(BaseForm): class OversightForm(BaseForm):
ko_first_name = StringField( ko_first_name = StringField(
translate("forms.task_order.oversight_first_name_label"), translate("forms.task_order.oversight_first_name_label"),
filters=[lambda x: x or None], filters=[remove_empty_string],
) )
ko_last_name = StringField( ko_last_name = StringField(
translate("forms.task_order.oversight_last_name_label"), translate("forms.task_order.oversight_last_name_label"),
filters=[lambda x: x or None], filters=[remove_empty_string],
) )
ko_email = StringField( ko_email = StringField(
translate("forms.task_order.oversight_email_label"), translate("forms.task_order.oversight_email_label"),
validators=[Optional(), Email()], validators=[Optional(), Email()],
filters=[lambda x: x or None], filters=[remove_empty_string],
) )
ko_phone_number = TelField( ko_phone_number = TelField(
translate("forms.task_order.oversight_phone_label"), translate("forms.task_order.oversight_phone_label"),
validators=[Optional(), PhoneNumber()], validators=[Optional(), PhoneNumber()],
filters=[lambda x: x or None], filters=[remove_empty_string],
) )
ko_dod_id = StringField( ko_dod_id = StringField(
translate("forms.task_order.oversight_dod_id_label"), translate("forms.task_order.oversight_dod_id_label"),
filters=[lambda x: x or None], filters=[remove_empty_string],
validators=[ validators=[
RequiredIf(lambda form: form._fields.get("ko_invite").data), RequiredIf(lambda form: form._fields.get("ko_invite").data),
Length(min=10), Length(min=10),
@ -186,20 +190,20 @@ class OversightForm(BaseForm):
am_cor = BooleanField(translate("forms.task_order.oversight_am_cor_label")) am_cor = BooleanField(translate("forms.task_order.oversight_am_cor_label"))
cor_first_name = StringField( cor_first_name = StringField(
translate("forms.task_order.oversight_first_name_label"), translate("forms.task_order.oversight_first_name_label"),
filters=[lambda x: x or None], filters=[remove_empty_string],
) )
cor_last_name = StringField( cor_last_name = StringField(
translate("forms.task_order.oversight_last_name_label"), translate("forms.task_order.oversight_last_name_label"),
filters=[lambda x: x or None], filters=[remove_empty_string],
) )
cor_email = StringField( cor_email = StringField(
translate("forms.task_order.oversight_email_label"), translate("forms.task_order.oversight_email_label"),
filters=[lambda x: x or None], filters=[remove_empty_string],
validators=[Optional(), Email()], validators=[Optional(), Email()],
) )
cor_phone_number = TelField( cor_phone_number = TelField(
translate("forms.task_order.oversight_phone_label"), translate("forms.task_order.oversight_phone_label"),
filters=[lambda x: x or None], filters=[remove_empty_string],
validators=[ validators=[
RequiredIf(lambda form: not form._fields.get("am_cor").data), RequiredIf(lambda form: not form._fields.get("am_cor").data),
Optional(), Optional(),
@ -208,7 +212,7 @@ class OversightForm(BaseForm):
) )
cor_dod_id = StringField( cor_dod_id = StringField(
translate("forms.task_order.oversight_dod_id_label"), translate("forms.task_order.oversight_dod_id_label"),
filters=[lambda x: x or None], filters=[remove_empty_string],
validators=[ validators=[
RequiredIf( RequiredIf(
lambda form: not form._fields.get("am_cor").data lambda form: not form._fields.get("am_cor").data
@ -221,25 +225,25 @@ class OversightForm(BaseForm):
so_first_name = StringField( so_first_name = StringField(
translate("forms.task_order.oversight_first_name_label"), translate("forms.task_order.oversight_first_name_label"),
filters=[lambda x: x or None], filters=[remove_empty_string],
) )
so_last_name = StringField( so_last_name = StringField(
translate("forms.task_order.oversight_last_name_label"), translate("forms.task_order.oversight_last_name_label"),
filters=[lambda x: x or None], filters=[remove_empty_string],
) )
so_email = StringField( so_email = StringField(
translate("forms.task_order.oversight_email_label"), translate("forms.task_order.oversight_email_label"),
filters=[lambda x: x or None], filters=[remove_empty_string],
validators=[Optional(), Email()], validators=[Optional(), Email()],
) )
so_phone_number = TelField( so_phone_number = TelField(
translate("forms.task_order.oversight_phone_label"), translate("forms.task_order.oversight_phone_label"),
filters=[lambda x: x or None], filters=[remove_empty_string],
validators=[Optional(), PhoneNumber()], validators=[Optional(), PhoneNumber()],
) )
so_dod_id = StringField( so_dod_id = StringField(
translate("forms.task_order.oversight_dod_id_label"), translate("forms.task_order.oversight_dod_id_label"),
filters=[lambda x: x or None], filters=[remove_empty_string],
validators=[ validators=[
RequiredIf(lambda form: form._fields.get("so_invite").data), RequiredIf(lambda form: form._fields.get("so_invite").data),
Length(min=10), Length(min=10),