Perform extra validation on financial verification step

This commit is contained in:
Patrick Smith 2018-07-17 16:29:02 -04:00
parent 2bca2f9ac8
commit f1ba2bcba6
3 changed files with 39 additions and 4 deletions

View File

@ -1,13 +1,40 @@
import tornado
from tornado.gen import Return
from wtforms.fields.html5 import EmailField
from wtforms.fields import StringField, SelectField
from wtforms.form import Form
from wtforms.validators import Required, Email
from .fields import NewlineListField
from .forms import ValidatedForm
@tornado.gen.coroutine
def validate_pe_id(field, existing_request, fundz_client):
response = yield fundz_client.get(
"/pe-number/{}".format(field.data),
raise_error=False,
)
if not response.ok:
field.errors.append(
"We couldn't find that PE number, but if you have double checked "
"it you can submit anyway. Your request will need to go through a "
"manual review."
)
return False
return True
class FinancialForm(ValidatedForm):
@tornado.gen.coroutine
def perform_extra_validation(self, existing_request, fundz_client):
valid = True
if existing_request['pe_id'] != self.pe_id.data:
valid = yield validate_pe_id(self.pe_id, existing_request, fundz_client)
raise Return(valid)
task_order_id = StringField(
"Task Order Number associated with this request.", validators=[Required()]
)

View File

@ -1,7 +1,12 @@
import tornado
from tornado.gen import Return
from wtforms_tornado import Form
class ValidatedForm(Form):
def validate_warnings(self, *args, **kwargs):
return True
@tornado.gen.coroutine
def perform_extra_validation(self, *args, **kwargs):
"""A coroutine that performs any applicable extra validation. Must
return True if the form is valid or False otherwise."""
raise Return(True)

View File

@ -53,7 +53,8 @@ class RequestNew(BaseHandler):
if jedi_flow.validate():
response = yield jedi_flow.create_or_update_request()
if response.ok:
if jedi_flow.validate_warnings():
valid = yield jedi_flow.validate_warnings()
if valid:
if jedi_flow.next_screen >= len(jedi_flow.screens):
where = "/requests"
else:
@ -143,11 +144,13 @@ class JEDIRequestFlow(object):
def validate(self):
return self.form.validate()
@tornado.gen.coroutine
def validate_warnings(self):
return self.form.validate_warnings(
valid = yield self.form.perform_extra_validation(
self.existing_request.get('body', {}).get(self.form_section),
self.fundz_client,
)
return valid
@property
def current_screen(self):