From 804ddc4db503bc065398d00c8b90972c76ca5c35 Mon Sep 17 00:00:00 2001 From: Montana Date: Fri, 11 Jan 2019 12:27:24 -0500 Subject: [PATCH] Allow user to rename task order and do no push othertext to DB --- atst/routes/task_orders/new.py | 30 +++++++------------ .../routes/task_orders/test_new_task_order.py | 12 ++++++++ 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/atst/routes/task_orders/new.py b/atst/routes/task_orders/new.py index 1a7ae25a..8835e7c5 100644 --- a/atst/routes/task_orders/new.py +++ b/atst/routes/task_orders/new.py @@ -62,21 +62,6 @@ class ShowTaskOrderWorkflow: return self._task_order - @property - def task_order_formdata(self): - task_order_dict = self.task_order.to_dictionary() - for field in task_order_dict: - if task_order_dict[field] is None: - task_order_dict[field] = "" - - # don't save other text in DB unless "other" is checked - if "other" not in task_order_dict["complexity"]: - task_order_dict["complexity_other"] = "" - if "other" not in task_order_dict["dev_team"]: - task_order_dict["dev_team_other"] = "" - - return task_order_dict - @property def form(self): form_type = ( @@ -137,12 +122,14 @@ class UpdateTaskOrderWorkflow(ShowTaskOrderWorkflow): def task_order_form_data(self): to_data = self.form.data.copy() if "portfolio_name" in to_data: - new_name = self.form.data["portfolio_name"] - old_name = self.task_order.to_dictionary()["portfolio_name"] - if not new_name is old_name: - Portfolios.update(self.task_order.portfolio, {"name": new_name}) to_data.pop("portfolio_name") + # don't save other text in DB unless "other" is checked + if "complexity" in to_data and "other" not in to_data["complexity"]: + to_data["complexity_other"] = "" + if "dev_team" in to_data and "other" not in to_data["dev_team"]: + to_data["dev_team_other"] = "" + return to_data def validate(self): @@ -150,6 +137,11 @@ class UpdateTaskOrderWorkflow(ShowTaskOrderWorkflow): def _update_task_order(self): if self.task_order: + if "portfolio_name" in self.form.data: + new_name = self.form.data["portfolio_name"] + old_name = self.task_order.to_dictionary()["portfolio_name"] + if not new_name is old_name: + Portfolios.update(self.task_order.portfolio, {"name": new_name}) TaskOrders.update(self.user, self.task_order, **self.task_order_form_data) else: pf = Portfolios.create(self.user, self.form.portfolio_name.data) diff --git a/tests/routes/task_orders/test_new_task_order.py b/tests/routes/task_orders/test_new_task_order.py index d1ab2e81..77ed8dc5 100644 --- a/tests/routes/task_orders/test_new_task_order.py +++ b/tests/routes/task_orders/test_new_task_order.py @@ -162,6 +162,18 @@ def test_update_task_order_with_existing_task_order(task_order): assert workflow.task_order.start_date.strftime("%m/%d/%Y") == to_data["start_date"] +def test_other_text_not_saved_if_other_not_checked(task_order): + to_data = { + **TaskOrderFactory.dictionary(), + "complexity": ["conus", "other"], + "complexity_other": "quite complex", + } + workflow = UpdateTaskOrderWorkflow( + task_order.creator, to_data, task_order_id=task_order.id + ) + workflow.update() + + def test_invite_officers_to_task_order(task_order, queue): to_data = { **TaskOrderFactory.dictionary(),