show or hide manual TO fields based on query param

This commit is contained in:
dandds 2018-08-20 15:51:32 -04:00
parent a574734a8b
commit 735b9b5179
4 changed files with 79 additions and 59 deletions

View File

@ -57,12 +57,7 @@ def validate_pe_id(field, existing_request):
return True
class FinancialForm(ValidatedForm):
def validate(self, *args, **kwargs):
if self.funding_type.data == "OTHER":
self.funding_type_other.validators.append(Required())
return super().validate(*args, **kwargs)
class BaseFinancialForm(ValidatedForm):
def reset(self):
"""
Reset UII info so that it can be de-parsed rendered properly.
@ -117,6 +112,17 @@ class FinancialForm(ValidatedForm):
"Contracting Officer Representative (COR) Office", validators=[Required()]
)
class FinancialForm(BaseFinancialForm):
pass
class ExtendedFinancialForm(BaseFinancialForm):
def validate(self, *args, **kwargs):
if self.funding_type.data == "OTHER":
self.funding_type_other.validators.append(Required())
return super().validate(*args, **kwargs)
funding_type = SelectField(
description="What is the source of funding?",
choices=[

View File

@ -3,15 +3,25 @@ from flask import request as http_request
from . import requests_bp
from atst.domain.requests import Requests
from atst.forms.financial import FinancialForm
from atst.forms.financial import FinancialForm, ExtendedFinancialForm
def financial_form(data):
if http_request.args.get("extended"):
return ExtendedFinancialForm(data=data)
else:
return FinancialForm(data=data)
@requests_bp.route("/requests/verify/<string:request_id>", methods=["GET"])
def financial_verification(request_id=None):
request = Requests.get(request_id)
form = FinancialForm(data=request.body.get("financial_verification"))
form = financial_form(request.body.get("financial_verification"))
return render_template(
"requests/financial_verification.html", f=form, request_id=request_id
"requests/financial_verification.html",
f=form,
request_id=request_id,
extended=http_request.args.get("extended"),
)
@ -19,9 +29,9 @@ def financial_verification(request_id=None):
def update_financial_verification(request_id):
post_data = http_request.form
existing_request = Requests.get(request_id)
form = FinancialForm(post_data)
form = financial_form(post_data)
rerender_args = dict(request_id=request_id, f=form)
rerender_args = dict(request_id=request_id, f=form, extended=http_request.args.get("extended"))
if form.validate():
request_data = {"financial_verification": form.data}
@ -31,11 +41,13 @@ def update_financial_verification(request_id):
Requests.update(request_id, request_data)
if valid:
return redirect(url_for("requests.financial_verification_submitted"))
else:
form.reset()
return render_template(
"requests/financial_verification.html", **rerender_args
)
else:
form.reset()
return render_template("requests/financial_verification.html", **rerender_args)

View File

@ -9,6 +9,13 @@
<financial inline-template v-bind:initial-data='{{ f.data|tojson }}'>
<div class="col">
{% if extended %}
{{ Alert('Task Order not found in EDA',
message="Since the Task Order (TO) number was not found in our system of record, EDA, please populate the additional fields in the form below.",
level='warning'
) }}
{% endif %}
<div class="panel">
<div class="panel__heading">
@ -35,6 +42,46 @@
<p>In order to get you access to the JEDI Cloud, we will need you to enter the details below that will help us verify and account for your Task Order.</p>
{% if extended %}
<fieldset class="form__sub-fields form__sub-fields--warning">
{{ OptionsInput(f.funding_type) }}
<template v-if="funding_type == 'OTHER'" v-cloak>
{{ TextInput(f.funding_type_other) }}
</template>
{{ TextInput(
f.clin_0001,placeholder="50,000",
validation='integer'
) }}
{{ TextInput(
f.clin_0003,placeholder="13,000",
validation='integer'
) }}
{{ TextInput(
f.clin_1001,placeholder="30,000",
validation='integer'
) }}
{{ TextInput(
f.clin_1003,placeholder="7,000",
validation='integer'
) }}
{{ TextInput(
f.clin_2001,placeholder="30,000",
validation='integer'
) }}
{{ TextInput(
f.clin_2003,placeholder="7,000",
validation='integer'
) }}
</fieldset>
{% endif %}
{{ TextInput(
f.task_order_id,
placeholder="e.g.: 1234567899C0001",
@ -83,51 +130,6 @@
{{ TextInput(f.office_cor,placeholder="e.g.: WHS") }}
<hr>
{{ Alert('Task Order not found in EDA',
message="Since the Task Order (TO) number was not found in our system of record, EDA, please populate the additional fields in the form below.",
level='warning'
) }}
<fieldset class="form__sub-fields form__sub-fields--warning">
{{ OptionsInput(f.funding_type) }}
<template v-if="funding_type == 'OTHER'" v-cloak>
{{ TextInput(f.funding_type_other) }}
</template>
{{ TextInput(
f.clin_0001,placeholder="50,000",
validation='integer'
) }}
{{ TextInput(
f.clin_0003,placeholder="13,000",
validation='integer'
) }}
{{ TextInput(
f.clin_1001,placeholder="30,000",
validation='integer'
) }}
{{ TextInput(
f.clin_1003,placeholder="7,000",
validation='integer'
) }}
{{ TextInput(
f.clin_2001,placeholder="30,000",
validation='integer'
) }}
{{ TextInput(
f.clin_2003,placeholder="7,000",
validation='integer'
) }}
</fieldset>
{% endautoescape %}
{% endblock form %}

View File

@ -1,6 +1,6 @@
import pytest
from atst.forms.financial import suggest_pe_id, FinancialForm
from atst.forms.financial import suggest_pe_id, FinancialForm, ExtendedFinancialForm
@pytest.mark.parametrize("input_,expected", [
@ -18,7 +18,7 @@ def test_funding_type_other_not_required_if_funding_type_is_not_other():
form_data = {
"funding_type": "PROC"
}
form = FinancialForm(data=form_data)
form = ExtendedFinancialForm(data=form_data)
form.validate()
assert "funding_type_other" not in form.errors
@ -27,7 +27,7 @@ def test_funding_type_other_required_if_funding_type_is_other():
form_data = {
"funding_type": "OTHER"
}
form = FinancialForm(data=form_data)
form = ExtendedFinancialForm(data=form_data)
form.validate()
assert "funding_type_other" in form.errors