Update TO form to account for new TO rules: alpha numeric, between 13 and 17 characters, dashes should be stripped, and coerce to uppercase

This commit is contained in:
leigh-mil
2020-01-23 16:25:03 -05:00
parent 204bf49ff4
commit 84d0a32694
5 changed files with 67 additions and 9 deletions

View File

@@ -10,11 +10,13 @@ from wtforms.fields.html5 import DateField
from wtforms.validators import (
Required,
Length,
Optional,
NumberRange,
ValidationError,
)
from flask_wtf import FlaskForm
import numbers
from atst.forms.validators import Number, AlphaNumeric
from .data import JEDI_CLIN_TYPES
@@ -60,6 +62,20 @@ def validate_date_in_range(form, field):
)
def remove_dashes(value):
if value:
return value.replace("-", "")
else:
return None
def coerce_upper(value):
if value:
return value.upper()
else:
return None
class CLINForm(FlaskForm):
jedi_clin_type = SelectField(
translate("task_orders.form.clin_type_label"),
@@ -149,8 +165,8 @@ class AttachmentForm(BaseForm):
class TaskOrderForm(BaseForm):
number = StringField(
label=translate("forms.task_order.number_description"),
filters=[remove_empty_string],
validators=[Number(), Length(max=13)],
filters=[remove_empty_string, remove_dashes, coerce_upper],
validators=[AlphaNumeric(), Length(min=13, max=17), Optional()],
)
pdf = FormField(
AttachmentForm,