@@ -12,7 +12,7 @@ from wtforms.fields.html5 import DateField, TelField
|
||||
from wtforms.widgets import ListWidget, CheckboxInput
|
||||
from wtforms.validators import Required, Length
|
||||
|
||||
from atst.forms.validators import IsNumber, PhoneNumber
|
||||
from atst.forms.validators import IsNumber, PhoneNumber, RequiredIfNot
|
||||
|
||||
from .forms import CacheableForm
|
||||
from .data import (
|
||||
@@ -120,17 +120,19 @@ class OversightForm(CacheableForm):
|
||||
validators=[Required(), Length(min=10), IsNumber()],
|
||||
)
|
||||
|
||||
am_cor = BooleanField(translate("forms.task_order.oversight_am_cor_label"))
|
||||
cor_first_name = StringField(
|
||||
translate("forms.task_order.oversight_first_name_label")
|
||||
)
|
||||
cor_last_name = StringField(translate("forms.task_order.oversight_last_name_label"))
|
||||
cor_email = StringField(translate("forms.task_order.oversight_email_label"))
|
||||
cor_phone_number = TelField(
|
||||
translate("forms.task_order.oversight_phone_label"), validators=[PhoneNumber()]
|
||||
translate("forms.task_order.oversight_phone_label"),
|
||||
validators=[RequiredIfNot("am_cor"), PhoneNumber()],
|
||||
)
|
||||
cor_dod_id = StringField(
|
||||
translate("forms.task_order.oversight_dod_id_label"),
|
||||
validators=[Required(), Length(min=10), IsNumber()],
|
||||
validators=[RequiredIfNot("am_cor"), Length(min=10), IsNumber()],
|
||||
)
|
||||
|
||||
so_first_name = StringField(
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import re
|
||||
from wtforms.validators import ValidationError
|
||||
from wtforms.validators import ValidationError, StopValidation
|
||||
import pendulum
|
||||
from datetime import datetime
|
||||
from atst.utils.localization import translate
|
||||
@@ -78,3 +78,28 @@ def ListItemsUnique(message=translate("forms.validators.list_items_unique_messag
|
||||
raise ValidationError(message)
|
||||
|
||||
return _list_items_unique
|
||||
|
||||
|
||||
def RequiredIfNot(other_field_name, message=translate("forms.validators.is_required")):
|
||||
""" A validator which makes a field required only if another field
|
||||
has a falsy value
|
||||
Args:
|
||||
other_field_name (str): the name of the field we check before
|
||||
determining if this field is required; if this other field is falsy,
|
||||
the field will be required
|
||||
message (str): an optional message to display if the field is
|
||||
required but hasNone value
|
||||
"""
|
||||
|
||||
def _required_if_not(form, field):
|
||||
other_field = form._fields.get(other_field_name)
|
||||
if other_field is None:
|
||||
raise Exception('no field named "%s" in form' % self.other_field_name)
|
||||
|
||||
if not bool(other_field.data):
|
||||
if field.data is None:
|
||||
raise ValidationError(message)
|
||||
else:
|
||||
raise StopValidation()
|
||||
|
||||
return _required_if_not
|
||||
|
@@ -78,6 +78,10 @@ class ShowTaskOrderWorkflow:
|
||||
if self._section["section"] == "app_info":
|
||||
self._form.complexity.data = self.task_order.complexity
|
||||
self._form.dev_team.data = self.task_order.dev_team
|
||||
elif self._section["section"] == "oversight":
|
||||
if self.user.dod_id == self.task_order.cor_dod_id:
|
||||
self._form.am_cor.data = True
|
||||
|
||||
else:
|
||||
self._form = self._section[form_type]()
|
||||
|
||||
@@ -133,6 +137,16 @@ class UpdateTaskOrderWorkflow(ShowTaskOrderWorkflow):
|
||||
if "dev_team" in to_data and "other" not in to_data["dev_team"]:
|
||||
to_data["dev_team_other"] = None
|
||||
|
||||
if self.form_data.get("am_cor"):
|
||||
cor_data = {
|
||||
"cor_first_name": self.user.first_name,
|
||||
"cor_last_name": self.user.last_name,
|
||||
"cor_email": self.user.email,
|
||||
"cor_phone_number": self.user.phone_number,
|
||||
"cor_dod_id": self.user.dod_id,
|
||||
}
|
||||
to_data = {**to_data, **cor_data}
|
||||
|
||||
return to_data
|
||||
|
||||
def validate(self):
|
||||
|
Reference in New Issue
Block a user