Add validation to form for enforcing chronological order of PoP start and end dates
This commit is contained in:
parent
0493078b33
commit
25ab64f748
@ -51,6 +51,16 @@ class CLINForm(FlaskForm):
|
||||
)
|
||||
loas = FieldList(StringField())
|
||||
|
||||
def validate(self, *args, **kwargs):
|
||||
valid = super().validate(*args, **kwargs)
|
||||
if self.start_date.data > self.end_date.data:
|
||||
self.start_date.errors.append(
|
||||
translate("forms.task_order.start_date_error")
|
||||
)
|
||||
return False
|
||||
else:
|
||||
return valid
|
||||
|
||||
|
||||
class TaskOrderForm(BaseForm):
|
||||
number = StringField(label=translate("forms.task_order.number_description"))
|
||||
|
@ -80,10 +80,10 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p class="usa-input-error-message" v-bind:class="{ 'form-has-errors': !isWithinDateRange }">
|
||||
{% if maxdate and mindate %}Date must be between {{mindate.strftime("%m/%d/%Y")}} and {{maxdate.strftime("%m/%d/%Y")}}{% endif %}
|
||||
{% if maxdate and not mindate %}Date must be before or on {{maxdate.strftime("%m/%d/%Y")}}{% endif %}
|
||||
{% if mindate and not maxdate %}Date must be after or on {{mindate.strftime("%m/%d/%Y")}}{% endif %}
|
||||
<p class="usa-input-error-message" v-bind:class='{% if field.errors %}"form-has-errors"{% endif %}'>
|
||||
{% if field.errors %}
|
||||
{{ field.errors[0] }}
|
||||
{% endif %}
|
||||
</p>
|
||||
</fieldset>
|
||||
</date-selector>
|
||||
|
@ -138,14 +138,15 @@
|
||||
|
||||
<div class="form-row">
|
||||
{% if fields %}
|
||||
<div class="form-col">
|
||||
<div class="form-col form-col--half">
|
||||
{{ DatePicker(fields.start_date, watch=True, optional=False) }}
|
||||
</div>
|
||||
<div class="form-col">
|
||||
<div class="form-col form-col--half">
|
||||
{{ DatePicker(fields.end_date, watch=True, optional=False) }}
|
||||
</div>
|
||||
|
||||
{% else %}
|
||||
<div class="form-col">
|
||||
<div class="form-col form-col--half">
|
||||
<date-selector :name-tag="'clins-' + clinIndex + '-start_date'" :watch='true' :optional='false' inline-template>
|
||||
<fieldset class="usa-input date-picker" v-bind:class="{ 'usa-input--success': isDateValid }">
|
||||
<legend>
|
||||
@ -209,7 +210,7 @@
|
||||
</date-selector>
|
||||
</div>
|
||||
|
||||
<div class="form-col">
|
||||
<div class="form-col form-col--half">
|
||||
<date-selector :name-tag="'clins-' + clinIndex + '-end_date'" :watch='true' :optional='false' inline-template>
|
||||
<fieldset class="usa-input date-picker" v-bind:class="{ 'usa-input--success': isDateValid }">
|
||||
<legend>
|
||||
|
@ -1,5 +1,8 @@
|
||||
import datetime
|
||||
|
||||
from atst.forms.task_order import CLINForm
|
||||
from atst.models import JEDICLINType
|
||||
from atst.utils.localization import translate
|
||||
|
||||
import tests.factories as factories
|
||||
|
||||
@ -9,3 +12,21 @@ def test_clin_form_jedi_clin_type():
|
||||
clin = factories.CLINFactory.create(jedi_clin_type=jedi_type)
|
||||
clin_form = CLINForm(obj=clin)
|
||||
assert clin_form.jedi_clin_type.data == jedi_type.value
|
||||
|
||||
|
||||
def test_clin_form_start_date_before_end_date():
|
||||
invalid_start = datetime.date(2020, 12, 12)
|
||||
invalid_end = datetime.date(2020, 1, 1)
|
||||
invalid_clin = factories.CLINFactory.create(
|
||||
start_date=invalid_start, end_date=invalid_end
|
||||
)
|
||||
clin_form = CLINForm(obj=invalid_clin)
|
||||
assert not clin_form.validate()
|
||||
assert translate("forms.task_order.start_date_error") in clin_form.start_date.errors
|
||||
valid_start = datetime.date(2020, 1, 1)
|
||||
valid_end = datetime.date(2020, 12, 12)
|
||||
valid_clin = factories.CLINFactory.create(
|
||||
start_date=valid_start, end_date=valid_end
|
||||
)
|
||||
valid_clin_form = CLINForm(obj=valid_clin)
|
||||
assert valid_clin_form.validate()
|
||||
|
@ -175,6 +175,7 @@ forms:
|
||||
number_description: Task order number (13 digits)
|
||||
scope_description: 'What do you plan to do on the cloud? Some examples might include migrating an existing application or creating a prototype. You don’t need to include a detailed plan of execution, but should list key requirements. This section will be reviewed by your contracting officer, but won’t be sent to the CCPO. <p>Not sure how to describe your scope? <a href="#">Read some examples</a> to get some inspiration.</p>'
|
||||
scope_label: Cloud project scope
|
||||
start_date_error: PoP start date must be before end date.
|
||||
start_date_label: Start of period of performance (PoP)
|
||||
team_experience:
|
||||
built_1: Built, migrated, or consulted on 1-2 applications
|
||||
|
Loading…
x
Reference in New Issue
Block a user