From d495619cb62aa4e55c4d3cf23ddb3c06459dadf8 Mon Sep 17 00:00:00 2001 From: Patrick Smith Date: Thu, 17 Jan 2019 08:47:23 -0500 Subject: [PATCH 1/3] Allow specifying custom actions in flashed messages --- atst/utils/flash.py | 5 ++++- templates/fragments/flash.html | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/atst/utils/flash.py b/atst/utils/flash.py index 4ba9ac42..9adf1499 100644 --- a/atst/utils/flash.py +++ b/atst/utils/flash.py @@ -115,4 +115,7 @@ def formatted_flash(message_name, **message_args): config = MESSAGES[message_name] title = render_template_string(config["title_template"], **message_args) message = render_template_string(config["message_template"], **message_args) - flash({"title": title, "message": message}, config["category"]) + actions = None + if "actions" in config: + actions = render_template_string(config["actions"], **message_args) + flash({"title": title, "message": message, "actions": actions}, config["category"]) diff --git a/templates/fragments/flash.html b/templates/fragments/flash.html index 518f27a5..49057352 100644 --- a/templates/fragments/flash.html +++ b/templates/fragments/flash.html @@ -7,7 +7,7 @@ {% with messages = get_flashed_messages(with_categories=true, category_filter=category_filter) %} {% if messages %} {% for category, message_config in messages %} - {{ Alert(message_config["title"], message=message_config.get("message"), level=category) }} + {{ Alert(message_config["title"], message=message_config.get("message"), actions=message_config.get("actions"), level=category) }} {% endfor %} {% endif %} {% endwith %} From a8ac5de968479977c02a5f18215affaa3163ad1e Mon Sep 17 00:00:00 2001 From: Patrick Smith Date: Thu, 17 Jan 2019 08:50:17 -0500 Subject: [PATCH 2/3] Show "Congrats" alert when completing TO form --- atst/routes/task_orders/invite.py | 9 +++++++-- atst/utils/flash.py | 20 ++++++++++++++++++++ styles/sections/_task_order.scss | 4 ++++ templates/portfolios/task_orders/show.html | 5 ++++- 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/atst/routes/task_orders/invite.py b/atst/routes/task_orders/invite.py index 1e8e40ac..ac40e0c2 100644 --- a/atst/routes/task_orders/invite.py +++ b/atst/routes/task_orders/invite.py @@ -8,7 +8,12 @@ from atst.utils.flash import formatted_flash as flash @task_orders_bp.route("/task_orders/invite/", methods=["POST"]) def invite(task_order_id): task_order = TaskOrders.get(g.current_user, task_order_id) - flash("task_order_submitted", task_order=task_order) + portfolio = task_order.portfolio + flash("task_order_congrats", portfolio=portfolio) return redirect( - url_for("portfolios.portfolio_members", portfolio_id=task_order.portfolio.id) + url_for( + "portfolios.view_task_order", + portfolio_id=task_order.portfolio_id, + task_order_id=task_order.id, + ) ) diff --git a/atst/utils/flash.py b/atst/utils/flash.py index 9adf1499..a64693e0 100644 --- a/atst/utils/flash.py +++ b/atst/utils/flash.py @@ -108,6 +108,26 @@ MESSAGES = { """, "category": "success", }, + "task_order_congrats": { + "title_template": "Congrats!", + "message_template": """ + You've created a new JEDI portfolio and jump started your first task order! + """, + "actions": """ + {% from "components/icon.html" import Icon %} + + """, + "category": "success", + }, } diff --git a/styles/sections/_task_order.scss b/styles/sections/_task_order.scss index faae653f..2260d8a8 100644 --- a/styles/sections/_task_order.scss +++ b/styles/sections/_task_order.scss @@ -59,6 +59,10 @@ .task-order-summary { + .alert .alert__actions { + margin-top: 2 * $gap; + } + .panel { width: 100%; } diff --git a/templates/portfolios/task_orders/show.html b/templates/portfolios/task_orders/show.html index 863c81da..38dadacf 100644 --- a/templates/portfolios/task_orders/show.html +++ b/templates/portfolios/task_orders/show.html @@ -59,7 +59,10 @@ {% endmacro %} +
+ {% include "fragments/flash.html" %} +

New Task Order

@@ -83,7 +86,7 @@
-
+

What's next?

{{ Step( From 87cd100c515d43a18253485f2c60f2231286e8a1 Mon Sep 17 00:00:00 2001 From: Patrick Smith Date: Thu, 17 Jan 2019 09:03:51 -0500 Subject: [PATCH 3/3] Fix test for task_orders.invite route --- tests/routes/task_orders/test_invite.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/routes/task_orders/test_invite.py b/tests/routes/task_orders/test_invite.py index 39cfeb76..6ee9fa30 100644 --- a/tests/routes/task_orders/test_invite.py +++ b/tests/routes/task_orders/test_invite.py @@ -1,11 +1,17 @@ import pytest from flask import url_for -from tests.factories import TaskOrderFactory +from tests.factories import PortfolioFactory, TaskOrderFactory -def test_invite(client): - to = TaskOrderFactory.create() +def test_invite(client, user_session): + portfolio = PortfolioFactory.create() + user_session(portfolio.owner) + to = TaskOrderFactory.create(portfolio=portfolio) response = client.post( url_for("task_orders.invite", task_order_id=to.id), follow_redirects=False ) + redirect = url_for( + "portfolios.view_task_order", portfolio_id=to.portfolio_id, task_order_id=to.id + ) + assert redirect in response.headers["Location"]