Combine form classes and rename as BaseForm
This commit is contained in:
parent
12776c7124
commit
dab13034d5
@ -2,13 +2,13 @@ from wtforms.fields.html5 import EmailField, TelField
|
||||
from wtforms.fields import StringField, TextAreaField
|
||||
from wtforms.validators import Email, Optional
|
||||
|
||||
from .forms import CacheableForm
|
||||
from .forms import BaseForm
|
||||
from .validators import Name, PhoneNumber
|
||||
|
||||
from atst.utils.localization import translate
|
||||
|
||||
|
||||
class CCPOReviewForm(CacheableForm):
|
||||
class CCPOReviewForm(BaseForm):
|
||||
comment = TextAreaField(
|
||||
translate("forms.ccpo_review.comment_label"),
|
||||
description=translate("forms.ccpo_review.comment_description"),
|
||||
|
@ -5,12 +5,12 @@ from wtforms.validators import Required
|
||||
|
||||
from atst.forms.validators import PhoneNumber
|
||||
|
||||
from .forms import CacheableForm
|
||||
from .forms import BaseForm
|
||||
from .data import REQUIRED_DISTRIBUTIONS
|
||||
from atst.utils.localization import translate
|
||||
|
||||
|
||||
class DD254Form(CacheableForm):
|
||||
class DD254Form(BaseForm):
|
||||
certifying_official = StringField(
|
||||
translate("forms.dd_254.certifying_official.label"),
|
||||
description=translate("forms.dd_254.certifying_official.description"),
|
||||
|
@ -5,7 +5,7 @@ from wtforms.fields import RadioField, StringField
|
||||
from wtforms.validators import Email, DataRequired, Optional
|
||||
|
||||
from .fields import SelectField
|
||||
from .forms import CacheableForm
|
||||
from .forms import BaseForm
|
||||
from .data import SERVICE_BRANCHES
|
||||
from atst.models.user import User
|
||||
from atst.utils.localization import translate
|
||||
@ -84,7 +84,7 @@ def inherit_user_field(field_name):
|
||||
return inherit_field(USER_FIELDS[field_name], required=required)
|
||||
|
||||
|
||||
class EditUserForm(CacheableForm):
|
||||
class EditUserForm(BaseForm):
|
||||
|
||||
first_name = inherit_user_field("first_name")
|
||||
last_name = inherit_user_field("last_name")
|
||||
|
@ -4,22 +4,16 @@ from flask import current_app, request as http_request
|
||||
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."""
|
||||
return True
|
||||
class BaseForm(FlaskForm):
|
||||
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().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
|
||||
|
||||
@ -28,11 +22,3 @@ class ValidatedForm(FlaskForm):
|
||||
if not valid:
|
||||
flash("form_errors")
|
||||
return valid
|
||||
|
||||
|
||||
class CacheableForm(ValidatedForm):
|
||||
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)
|
||||
|
@ -1,11 +1,11 @@
|
||||
from wtforms.fields import TextAreaField
|
||||
from wtforms.validators import InputRequired
|
||||
|
||||
from .forms import CacheableForm
|
||||
from .forms import BaseForm
|
||||
from atst.utils.localization import translate
|
||||
|
||||
|
||||
class InternalCommentForm(CacheableForm):
|
||||
class InternalCommentForm(BaseForm):
|
||||
text = TextAreaField(
|
||||
translate("forms.internal_comment.text_label"),
|
||||
default="",
|
||||
|
@ -4,12 +4,12 @@ from wtforms.fields.html5 import DateField
|
||||
from wtforms.fields import StringField, TextAreaField, FileField, FieldList
|
||||
from wtforms.validators import Optional, Length
|
||||
|
||||
from .forms import CacheableForm
|
||||
from .forms import BaseForm
|
||||
|
||||
from atst.utils.localization import translate
|
||||
|
||||
|
||||
class KOReviewForm(CacheableForm):
|
||||
class KOReviewForm(BaseForm):
|
||||
start_date = DateField(
|
||||
translate("forms.ko_review.start_date_label"), format="%m/%d/%Y"
|
||||
)
|
||||
|
@ -5,7 +5,7 @@ from wtforms.validators import Email, Length, Optional
|
||||
|
||||
from atst.forms.validators import IsNumber, PhoneNumber
|
||||
|
||||
from .forms import CacheableForm
|
||||
from .forms import BaseForm
|
||||
from .fields import FormFieldWrapper
|
||||
|
||||
|
||||
@ -18,7 +18,7 @@ class OfficerForm(FlaskForm):
|
||||
invite = BooleanField("Invite to Task Order Builder")
|
||||
|
||||
|
||||
class EditTaskOrderOfficersForm(CacheableForm):
|
||||
class EditTaskOrderOfficersForm(BaseForm):
|
||||
|
||||
contracting_officer = FormFieldWrapper(OfficerForm)
|
||||
contracting_officer_representative = FormFieldWrapper(OfficerForm)
|
||||
|
@ -1,11 +1,11 @@
|
||||
from wtforms.fields import StringField
|
||||
from wtforms.validators import Length
|
||||
|
||||
from .forms import CacheableForm
|
||||
from .forms import BaseForm
|
||||
from atst.utils.localization import translate
|
||||
|
||||
|
||||
class PortfolioForm(CacheableForm):
|
||||
class PortfolioForm(BaseForm):
|
||||
name = StringField(
|
||||
translate("forms.portfolio.name_label"),
|
||||
validators=[
|
||||
|
@ -15,7 +15,7 @@ from flask_wtf.file import FileAllowed
|
||||
|
||||
from atst.forms.validators import IsNumber, PhoneNumber, RequiredIf
|
||||
|
||||
from .forms import CacheableForm
|
||||
from .forms import BaseForm
|
||||
from .data import (
|
||||
SERVICE_BRANCHES,
|
||||
APP_MIGRATION,
|
||||
@ -27,7 +27,7 @@ from .data import (
|
||||
from atst.utils.localization import translate
|
||||
|
||||
|
||||
class AppInfoForm(CacheableForm):
|
||||
class AppInfoForm(BaseForm):
|
||||
portfolio_name = StringField(
|
||||
translate("forms.task_order.portfolio_name_label"),
|
||||
description=translate("forms.task_order.portfolio_name_description"),
|
||||
@ -88,7 +88,7 @@ class AppInfoForm(CacheableForm):
|
||||
)
|
||||
|
||||
|
||||
class FundingForm(CacheableForm):
|
||||
class FundingForm(BaseForm):
|
||||
performance_length = SelectField(
|
||||
translate("forms.task_order.performance_length.label"),
|
||||
choices=PERIOD_OF_PERFORMANCE_LENGTH,
|
||||
@ -134,7 +134,7 @@ class UnclassifiedFundingForm(FundingForm):
|
||||
)
|
||||
|
||||
|
||||
class OversightForm(CacheableForm):
|
||||
class OversightForm(BaseForm):
|
||||
ko_first_name = StringField(
|
||||
translate("forms.task_order.oversight_first_name_label")
|
||||
)
|
||||
@ -220,11 +220,11 @@ class OversightForm(CacheableForm):
|
||||
)
|
||||
|
||||
|
||||
class ReviewForm(CacheableForm):
|
||||
class ReviewForm(BaseForm):
|
||||
pass
|
||||
|
||||
|
||||
class SignatureForm(CacheableForm):
|
||||
class SignatureForm(BaseForm):
|
||||
level_of_warrant = DecimalField(
|
||||
translate("task_orders.sign.level_of_warrant_label"),
|
||||
description=translate("task_orders.sign.level_of_warrant_description"),
|
||||
|
Loading…
x
Reference in New Issue
Block a user