Merge pull request #560 from dod-ccpo/ko-dod-id-toggle
Toggle DOD ID Input For Officers
This commit is contained in:
@@ -10,9 +10,9 @@ from wtforms.fields import (
|
||||
)
|
||||
from wtforms.fields.html5 import DateField, TelField
|
||||
from wtforms.widgets import ListWidget, CheckboxInput
|
||||
from wtforms.validators import Required, Length
|
||||
from wtforms.validators import Length
|
||||
|
||||
from atst.forms.validators import IsNumber, PhoneNumber, RequiredIfNot
|
||||
from atst.forms.validators import IsNumber, PhoneNumber, RequiredIf
|
||||
|
||||
from .forms import CacheableForm
|
||||
from .data import (
|
||||
@@ -117,7 +117,11 @@ class OversightForm(CacheableForm):
|
||||
)
|
||||
ko_dod_id = StringField(
|
||||
translate("forms.task_order.oversight_dod_id_label"),
|
||||
validators=[Required(), Length(min=10), IsNumber()],
|
||||
validators=[
|
||||
RequiredIf(lambda form: form._fields.get("ko_invite").data),
|
||||
Length(min=10),
|
||||
IsNumber(),
|
||||
],
|
||||
)
|
||||
|
||||
am_cor = BooleanField(translate("forms.task_order.oversight_am_cor_label"))
|
||||
@@ -128,11 +132,21 @@ class OversightForm(CacheableForm):
|
||||
cor_email = StringField(translate("forms.task_order.oversight_email_label"))
|
||||
cor_phone_number = TelField(
|
||||
translate("forms.task_order.oversight_phone_label"),
|
||||
validators=[RequiredIfNot("am_cor"), PhoneNumber()],
|
||||
validators=[
|
||||
RequiredIf(lambda form: not form._fields.get("am_cor").data),
|
||||
PhoneNumber(),
|
||||
],
|
||||
)
|
||||
cor_dod_id = StringField(
|
||||
translate("forms.task_order.oversight_dod_id_label"),
|
||||
validators=[RequiredIfNot("am_cor"), Length(min=10), IsNumber()],
|
||||
validators=[
|
||||
RequiredIf(
|
||||
lambda form: not form._fields.get("am_cor").data
|
||||
and form._fields.get("cor_invite").data
|
||||
),
|
||||
Length(min=10),
|
||||
IsNumber(),
|
||||
],
|
||||
)
|
||||
|
||||
so_first_name = StringField(
|
||||
@@ -145,7 +159,11 @@ class OversightForm(CacheableForm):
|
||||
)
|
||||
so_dod_id = StringField(
|
||||
translate("forms.task_order.oversight_dod_id_label"),
|
||||
validators=[Required(), Length(min=10), IsNumber()],
|
||||
validators=[
|
||||
RequiredIf(lambda form: form._fields.get("so_invite").data),
|
||||
Length(min=10),
|
||||
IsNumber(),
|
||||
],
|
||||
)
|
||||
|
||||
ko_invite = BooleanField(
|
||||
|
||||
@@ -80,26 +80,22 @@ def ListItemsUnique(message=translate("forms.validators.list_items_unique_messag
|
||||
return _list_items_unique
|
||||
|
||||
|
||||
def RequiredIfNot(other_field_name, message=translate("forms.validators.is_required")):
|
||||
def RequiredIf(criteria_function, message=translate("forms.validators.is_required")):
|
||||
""" A validator which makes a field required only if another field
|
||||
has a falsy value
|
||||
has a truthy 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
|
||||
criteria_function (function): calling this function on form results
|
||||
in a boolean value that we want to check against;
|
||||
if it's True, we require the field
|
||||
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):
|
||||
def _required_if(form, field):
|
||||
if criteria_function(form):
|
||||
if field.data is None:
|
||||
raise ValidationError(message)
|
||||
else:
|
||||
raise StopValidation()
|
||||
|
||||
return _required_if_not
|
||||
return _required_if
|
||||
|
||||
@@ -81,6 +81,12 @@ class ShowTaskOrderWorkflow:
|
||||
elif self._section["section"] == "oversight":
|
||||
if self.user.dod_id == self.task_order.cor_dod_id:
|
||||
self._form.am_cor.data = True
|
||||
if self.task_order.contracting_officer:
|
||||
self._form.ko_invite.data = True
|
||||
if self.task_order.contracting_officer_representative:
|
||||
self._form.cor_invite.data = True
|
||||
if self.task_order.security_officer:
|
||||
self._form.so_invite.data = True
|
||||
|
||||
else:
|
||||
self._form = self._section[form_type]()
|
||||
|
||||
Reference in New Issue
Block a user