Files
atst/atst/forms/portfolio.py
graham-dds 156d733aee Add missing regex and validation for StringFields
This commit adds further validation for StringFields that were missing
it. This mostly amounted to being Regex patters and max lengths.
2020-01-22 15:20:18 -05:00

47 lines
1.3 KiB
Python

from wtforms.fields import (
SelectMultipleField,
StringField,
TextAreaField,
)
from wtforms.validators import Length, InputRequired
from atst.forms.validators import Name
from wtforms.widgets import ListWidget, CheckboxInput
from .forms import BaseForm
from atst.utils.localization import translate
from .data import SERVICE_BRANCHES
class PortfolioForm(BaseForm):
name = StringField(
translate("forms.portfolio.name.label"),
validators=[
Length(
min=4,
max=100,
message=translate("forms.portfolio.name.length_validation_message"),
),
Name(),
],
)
description = TextAreaField(
translate("forms.portfolio.description.label"), validators=[Length(max=1_000)]
)
class PortfolioCreationForm(PortfolioForm):
defense_component = SelectMultipleField(
translate("forms.portfolio.defense_component.title"),
choices=SERVICE_BRANCHES,
widget=ListWidget(prefix_label=False),
option_widget=CheckboxInput(),
validators=[
InputRequired(
message=translate(
"forms.portfolio.defense_component.validation_message"
)
)
],
)