DRY out pe_number and task_order_number errors
This commit is contained in:
parent
789e5c0906
commit
aef4878a39
@ -34,6 +34,17 @@ class FinancialVerificationBase(object):
|
|||||||
else:
|
else:
|
||||||
return FinancialForm(formdata=mdict)
|
return FinancialForm(formdata=mdict)
|
||||||
|
|
||||||
|
def _apply_pe_number_error(self, field):
|
||||||
|
suggestion = self.pe_validator.suggest_pe_id(field.data)
|
||||||
|
error_str = (
|
||||||
|
"We couldn't find that PE number. {}"
|
||||||
|
"If you have double checked it you can submit anyway. "
|
||||||
|
"Your request will need to go through a manual review."
|
||||||
|
).format('Did you mean "{}"? '.format(suggestion) if suggestion else "")
|
||||||
|
field.errors += (error_str,)
|
||||||
|
|
||||||
|
def _apply_task_order_number_error(self, field):
|
||||||
|
field.errors += ("Task Order number not found",)
|
||||||
|
|
||||||
class GetFinancialVerificationForm(FinancialVerificationBase):
|
class GetFinancialVerificationForm(FinancialVerificationBase):
|
||||||
def __init__(self, user, request, is_extended=False):
|
def __init__(self, user, request, is_extended=False):
|
||||||
@ -76,17 +87,11 @@ class UpdateFinancialVerification(FinancialVerificationBase):
|
|||||||
should_update = False
|
should_update = False
|
||||||
|
|
||||||
if not self.pe_validator.validate(self.request, form.pe_id.data):
|
if not self.pe_validator.validate(self.request, form.pe_id.data):
|
||||||
suggestion = self.pe_validator.suggest_pe_id(form.pe_id.data)
|
self._apply_pe_number_error(form.pe_id)
|
||||||
error_str = (
|
|
||||||
"We couldn't find that PE number. {}"
|
|
||||||
"If you have double checked it you can submit anyway. "
|
|
||||||
"Your request will need to go through a manual review."
|
|
||||||
).format('Did you mean "{}"? '.format(suggestion) if suggestion else "")
|
|
||||||
form.pe_id.errors += (error_str,)
|
|
||||||
should_submit = False
|
should_submit = False
|
||||||
|
|
||||||
if not self.task_order_validator.validate(form.task_order_number.data):
|
if not self.task_order_validator.validate(form.task_order_number.data):
|
||||||
form.task_order_number.errors += ("Task Order number not found",)
|
self._apply_task_order_number_error(form.task_order_number)
|
||||||
should_submit = False
|
should_submit = False
|
||||||
|
|
||||||
if should_update:
|
if should_update:
|
||||||
@ -141,17 +146,11 @@ class SaveFinancialVerificationDraft(FinancialVerificationBase):
|
|||||||
valid = False
|
valid = False
|
||||||
|
|
||||||
if valid and form.pe_id.data and not self.pe_validator.validate(self.request, form.pe_id.data):
|
if valid and form.pe_id.data and not self.pe_validator.validate(self.request, form.pe_id.data):
|
||||||
suggestion = self.pe_validator.suggest_pe_id(form.pe_id.data)
|
self._apply_pe_number_error(form.pe_id)
|
||||||
error_str = (
|
|
||||||
"We couldn't find that PE number. {}"
|
|
||||||
"If you have double checked it you can submit anyway. "
|
|
||||||
"Your request will need to go through a manual review."
|
|
||||||
).format('Did you mean "{}"? '.format(suggestion) if suggestion else "")
|
|
||||||
form.pe_id.errors += (error_str,)
|
|
||||||
valid = False
|
valid = False
|
||||||
|
|
||||||
if valid and form.task_order_number.data and not self.task_order_validator.validate(form.task_order_number.data):
|
if valid and form.task_order_number.data and not self.task_order_validator.validate(form.task_order_number.data):
|
||||||
form.task_order_number.errors += ("Task Order number not found",)
|
self._apply_task_order_number_error(form.task_order_number)
|
||||||
valid = False
|
valid = False
|
||||||
|
|
||||||
if not valid:
|
if not valid:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user