From 9883bde00cefbee585451a474b369144a7c77ea5 Mon Sep 17 00:00:00 2001 From: Patrick Smith Date: Tue, 8 Jan 2019 17:19:19 -0500 Subject: [PATCH 1/5] Remove unneccesary flash The flash is in the base 'task_order/_new.html' template, so it doesn't need to be included in the section as well. --- templates/task_orders/new/app_info.html | 2 -- templates/task_orders/new/funding.html | 2 -- templates/task_orders/new/oversight.html | 2 -- templates/task_orders/new/review.html | 2 -- 4 files changed, 8 deletions(-) diff --git a/templates/task_orders/new/app_info.html b/templates/task_orders/new/app_info.html index 9005bc2b..9e01a1fc 100644 --- a/templates/task_orders/new/app_info.html +++ b/templates/task_orders/new/app_info.html @@ -11,8 +11,6 @@ {% block form %} -{% include "fragments/flash.html" %} -

Basic Information

{{ TextInput(form.portfolio_name, placeholder="The name of your office or organization") }} {{ TextInput(form.scope, paragraph=True) }} diff --git a/templates/task_orders/new/funding.html b/templates/task_orders/new/funding.html index 701c2b75..23586216 100644 --- a/templates/task_orders/new/funding.html +++ b/templates/task_orders/new/funding.html @@ -10,8 +10,6 @@ {% block form %} -{% include "fragments/flash.html" %} -
diff --git a/templates/task_orders/new/oversight.html b/templates/task_orders/new/oversight.html index 59ea3797..102d1c84 100644 --- a/templates/task_orders/new/oversight.html +++ b/templates/task_orders/new/oversight.html @@ -9,8 +9,6 @@ {% block form %} -{% include "fragments/flash.html" %} -

Contracting Officer (KO) Information

{{ UserInfo(form.ko_first_name, form.ko_last_name, form.ko_email, form.ko_dod_id) }} diff --git a/templates/task_orders/new/review.html b/templates/task_orders/new/review.html index 34a8d28c..7ca973a1 100644 --- a/templates/task_orders/new/review.html +++ b/templates/task_orders/new/review.html @@ -10,8 +10,6 @@ {% block form %} -{% include "fragments/flash.html" %} - {% macro TOEditLink(screen=1) %} {% if task_order %} {{ EditLink(url_for("task_orders.new", screen=screen, task_order_id=task_order.id)) }} From 3a5c55410c8ec9cdc336a4f16dd0eb208fe67d42 Mon Sep 17 00:00:00 2001 From: Patrick Smith Date: Tue, 8 Jan 2019 17:32:13 -0500 Subject: [PATCH 2/5] Show errors on new task order form when fields are invalid Form errors were not being shown because a new form instance was being created each time the `form` property was being called. Since the `validate` method on the form adds the errors to the form instance, this was causing no errors to be shown even if the form were invalid. --- atst/routes/task_orders/new.py | 3 ++- .../routes/task_orders/test_new_task_order.py | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/atst/routes/task_orders/new.py b/atst/routes/task_orders/new.py index 9534fe12..ddbb477e 100644 --- a/atst/routes/task_orders/new.py +++ b/atst/routes/task_orders/new.py @@ -108,10 +108,11 @@ class UpdateTaskOrderWorkflow(ShowTaskOrderWorkflow): self.task_order_id = task_order_id self._task_order = None self._section = TASK_ORDER_SECTIONS[screen - 1] + self._form = self._section["form"](self.form_data) @property def form(self): - return self._section["form"](self.form_data) + return self._form @property def workspace(self): diff --git a/tests/routes/task_orders/test_new_task_order.py b/tests/routes/task_orders/test_new_task_order.py index 462fabea..000e280d 100644 --- a/tests/routes/task_orders/test_new_task_order.py +++ b/tests/routes/task_orders/test_new_task_order.py @@ -70,6 +70,28 @@ def test_create_new_task_order(client, user_session): assert url_for("task_orders.new", screen=4) in response.headers["Location"] +def test_task_order_form_shows_errors(client, user_session): + creator = UserFactory.create() + user_session(creator) + + to = TaskOrderFactory.create() + + task_order_data = TaskOrderFactory.dictionary() + funding_data = slice_data_for_section(task_order_data, "funding") + funding_data = serialize_dates(funding_data) + funding_data.update({"clin_01": "one milllllion dollars"}) + + response = client.post( + url_for("task_orders.update", screen=2, task_order_id=to.id), + data=funding_data, + follow_redirects=False, + ) + + body = response.data.decode() + assert "There were some errors" in body + assert "Not a valid integer" in body + + def test_show_task_order(): workflow = ShowTaskOrderWorkflow() assert workflow.task_order is None From 7b2e74f2f55501f46cfb10aa75137feb45edb655 Mon Sep 17 00:00:00 2001 From: Patrick Smith Date: Tue, 8 Jan 2019 17:51:49 -0500 Subject: [PATCH 3/5] Default to $0 for classified clins when unclassified --- atst/forms/task_order.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/atst/forms/task_order.py b/atst/forms/task_order.py index fb10774e..5c062ae6 100644 --- a/atst/forms/task_order.py +++ b/atst/forms/task_order.py @@ -85,6 +85,11 @@ class UnclassifiedFundingForm(FundingForm): clin_02 = IntegerField("CLIN 02: Classified (available soon)") clin_04 = IntegerField("CLIN 04: Classified (available soon)") + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.clin_02.data = "0" + self.clin_04.data = "0" + class OversightForm(CacheableForm): ko_first_name = StringField("First Name") From b61a331ce6c2559354ba18ac57d9a2459d6fe2de Mon Sep 17 00:00:00 2001 From: Patrick Smith Date: Tue, 8 Jan 2019 18:16:46 -0500 Subject: [PATCH 4/5] Use `deepcopy` to copy form section info Previously, copying the form sections was using `list.copy` which creates a shallow copy of the list. Since the `TASK_ORDER_SECTIONS` list contains a couple dictionaries, this was just creating another list with references to the same dictionaries. Therefore, when a section was marked as completed, it was updated globally and visiting the new task order without filling anything out would show some sections as completed. --- atst/routes/task_orders/new.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/atst/routes/task_orders/new.py b/atst/routes/task_orders/new.py index ddbb477e..eb542340 100644 --- a/atst/routes/task_orders/new.py +++ b/atst/routes/task_orders/new.py @@ -1,3 +1,5 @@ +from copy import deepcopy + from flask import ( request as http_request, render_template, @@ -90,7 +92,7 @@ class ShowTaskOrderWorkflow: @property def display_screens(self): - screen_info = TASK_ORDER_SECTIONS.copy() + screen_info = deepcopy(TASK_ORDER_SECTIONS) if self.task_order: for section in screen_info: From b3cdfd730d646c9e0df819db3483e1526c635d9a Mon Sep 17 00:00:00 2001 From: Patrick Smith Date: Tue, 8 Jan 2019 18:21:11 -0500 Subject: [PATCH 5/5] Don't show success/error icon on disabled fields --- templates/components/text_input.html | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/templates/components/text_input.html b/templates/components/text_input.html index 78b858b0..21a0839d 100644 --- a/templates/components/text_input.html +++ b/templates/components/text_input.html @@ -37,8 +37,10 @@ {{ description | safe }} {% endif %} - {{ Icon('alert',classes="icon-validation") }} - {{ Icon('ok',classes="icon-validation") }} + {% if not disabled %} + {{ Icon('alert',classes="icon-validation") }} + {{ Icon('ok',classes="icon-validation") }} + {% endif %}