Validate form warnings with existing request and fundz client
This commit is contained in:
parent
db097b211f
commit
2bca2f9ac8
@ -3,5 +3,5 @@ from wtforms_tornado import Form
|
|||||||
|
|
||||||
class ValidatedForm(Form):
|
class ValidatedForm(Form):
|
||||||
|
|
||||||
def validate_warnings(self, requests_client=None):
|
def validate_warnings(self, *args, **kwargs):
|
||||||
return True
|
return True
|
||||||
|
@ -13,6 +13,14 @@ class RequestNew(BaseHandler):
|
|||||||
def initialize(self, page, requests_client, fundz_client):
|
def initialize(self, page, requests_client, fundz_client):
|
||||||
self.page = page
|
self.page = page
|
||||||
self.requests_client = requests_client
|
self.requests_client = requests_client
|
||||||
|
self.fundz_client = fundz_client
|
||||||
|
|
||||||
|
@tornado.gen.coroutine
|
||||||
|
def get_existing_request(self, current_user, request_id):
|
||||||
|
request = yield self.requests_client.get(
|
||||||
|
"/users/{}/requests/{}".format(current_user["id"], request_id),
|
||||||
|
)
|
||||||
|
return request.json
|
||||||
|
|
||||||
@tornado.web.authenticated
|
@tornado.web.authenticated
|
||||||
@tornado.gen.coroutine
|
@tornado.gen.coroutine
|
||||||
@ -20,8 +28,16 @@ class RequestNew(BaseHandler):
|
|||||||
self.check_xsrf_cookie()
|
self.check_xsrf_cookie()
|
||||||
screen = int(screen)
|
screen = int(screen)
|
||||||
post_data = self.request.arguments
|
post_data = self.request.arguments
|
||||||
|
current_user = self.get_current_user()
|
||||||
|
existing_request = yield self.get_existing_request(current_user, request_id)
|
||||||
jedi_flow = JEDIRequestFlow(
|
jedi_flow = JEDIRequestFlow(
|
||||||
self.requests_client, screen, post_data=post_data, request_id=request_id
|
self.requests_client,
|
||||||
|
self.fundz_client,
|
||||||
|
screen,
|
||||||
|
post_data=post_data,
|
||||||
|
request_id=request_id,
|
||||||
|
current_user=current_user,
|
||||||
|
existing_request=existing_request,
|
||||||
)
|
)
|
||||||
|
|
||||||
rerender_args = dict(
|
rerender_args = dict(
|
||||||
@ -35,7 +51,7 @@ class RequestNew(BaseHandler):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if jedi_flow.validate():
|
if jedi_flow.validate():
|
||||||
response = yield jedi_flow.create_or_update_request(self.get_current_user())
|
response = yield jedi_flow.create_or_update_request()
|
||||||
if response.ok:
|
if response.ok:
|
||||||
if jedi_flow.validate_warnings():
|
if jedi_flow.validate_warnings():
|
||||||
if jedi_flow.next_screen >= len(jedi_flow.screens):
|
if jedi_flow.next_screen >= len(jedi_flow.screens):
|
||||||
@ -73,7 +89,7 @@ class RequestNew(BaseHandler):
|
|||||||
request = response.json
|
request = response.json
|
||||||
|
|
||||||
jedi_flow = JEDIRequestFlow(
|
jedi_flow = JEDIRequestFlow(
|
||||||
self.requests_client, screen, request, request_id=request_id
|
self.requests_client, self.fundz_client, screen, request, request_id=request_id
|
||||||
)
|
)
|
||||||
|
|
||||||
self.render(
|
self.render(
|
||||||
@ -93,12 +109,16 @@ class JEDIRequestFlow(object):
|
|||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
requests_client,
|
requests_client,
|
||||||
|
fundz_client,
|
||||||
current_step,
|
current_step,
|
||||||
request=None,
|
request=None,
|
||||||
post_data=None,
|
post_data=None,
|
||||||
request_id=None,
|
request_id=None,
|
||||||
|
current_user=None,
|
||||||
|
existing_request=None,
|
||||||
):
|
):
|
||||||
self.requests_client = requests_client
|
self.requests_client = requests_client
|
||||||
|
self.fundz_client = fundz_client
|
||||||
|
|
||||||
self.current_step = current_step
|
self.current_step = current_step
|
||||||
self.request = request
|
self.request = request
|
||||||
@ -109,6 +129,9 @@ class JEDIRequestFlow(object):
|
|||||||
self.request_id = request_id
|
self.request_id = request_id
|
||||||
self.form = self._form()
|
self.form = self._form()
|
||||||
|
|
||||||
|
self.current_user = current_user
|
||||||
|
self.existing_request = existing_request
|
||||||
|
|
||||||
def _form(self):
|
def _form(self):
|
||||||
if self.is_post:
|
if self.is_post:
|
||||||
return self.form_class()(self.post_data)
|
return self.form_class()(self.post_data)
|
||||||
@ -121,7 +144,10 @@ class JEDIRequestFlow(object):
|
|||||||
return self.form.validate()
|
return self.form.validate()
|
||||||
|
|
||||||
def validate_warnings(self):
|
def validate_warnings(self):
|
||||||
return self.form.validate_warnings(self.requests_client)
|
return self.form.validate_warnings(
|
||||||
|
self.existing_request.get('body', {}).get(self.form_section),
|
||||||
|
self.fundz_client,
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_screen(self):
|
def current_screen(self):
|
||||||
@ -201,9 +227,9 @@ class JEDIRequestFlow(object):
|
|||||||
]
|
]
|
||||||
|
|
||||||
@tornado.gen.coroutine
|
@tornado.gen.coroutine
|
||||||
def create_or_update_request(self, user):
|
def create_or_update_request(self):
|
||||||
request_data = {
|
request_data = {
|
||||||
"creator_id": user["id"],
|
"creator_id": self.current_user["id"],
|
||||||
"request": {self.form_section: self.form.data},
|
"request": {self.form_section: self.form.data},
|
||||||
}
|
}
|
||||||
if self.request_id:
|
if self.request_id:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user