From 80e0832f7d5ecc2b1a4b8781c16bde4af2512bc0 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Tue, 5 Jul 2016 11:39:07 +0100 Subject: [PATCH] Make a function for parsing `help` query param Our templates are a littered with `request.args.get('help', '0')`. This commit refactors these into a single helper method, which can be used by the view functions, then passed to the template. This makes the templates cleaner, and should make it easier to refactor `help` out of the query parameters entirely in the future. --- app/main/views/jobs.py | 7 +++++-- app/main/views/send.py | 8 +++++--- app/templates/main_nav.html | 10 +++++----- app/templates/partials/jobs/notifications.html | 2 +- app/templates/views/check.html | 2 +- app/templates/views/send-test.html | 2 +- app/utils.py | 4 ++++ 7 files changed, 22 insertions(+), 13 deletions(-) diff --git a/app/main/views/jobs.py b/app/main/views/jobs.py index 4d6e71a60..e1baa38c4 100644 --- a/app/main/views/jobs.py +++ b/app/main/views/jobs.py @@ -28,6 +28,7 @@ from app.utils import ( user_has_permissions, generate_notifications_csv) from app.statistics_utils import sum_of_statistics, statistics_by_state, add_rate_to_jobs +from app.utils import get_help_argument def _parse_filter_args(filter_dict): @@ -98,7 +99,8 @@ def view_job(service_id, job_id): job_id=job['id'], status=request.args.get('status', '') ), - partials=get_job_partials(job) + partials=get_job_partials(job), + help=get_help_argument() ) @@ -311,7 +313,8 @@ def get_job_partials(job): notifications=notification_api_client.get_notifications_for_service( job['service'], job['id'], status=filter_args.get('status') )['notifications'], - status=request.args.get('status', '') + status=request.args.get('status', ''), + help=get_help_argument() ), 'status': render_template( 'partials/jobs/status.html', diff --git a/app/main/views/send.py b/app/main/views/send.py index faeb3acf4..07aa0eb52 100644 --- a/app/main/views/send.py +++ b/app/main/views/send.py @@ -29,7 +29,7 @@ from app.main.uploader import ( s3download ) from app import job_api_client, service_api_client, current_service, user_api_client, statistics_api_client -from app.utils import user_has_permissions, get_errors_for_csv, Spreadsheet +from app.utils import user_has_permissions, get_errors_for_csv, Spreadsheet, get_help_argument def get_page_headings(template_type): @@ -181,7 +181,8 @@ def send_test(service_id, template_id): 'views/send-test.html', template=template, recipient_column=first_column_heading[template.template_type], - example=[get_example_csv_rows(template, use_example_as_example=False)] + example=[get_example_csv_rows(template, use_example_as_example=False)], + help=get_help_argument() ) @@ -278,7 +279,8 @@ def check_messages(service_id, template_type, upload_id): upload_id=upload_id, form=CsvUploadForm(), statistics=statistics, - back_link=back_link + back_link=back_link, + help=get_help_argument() ) diff --git a/app/templates/main_nav.html b/app/templates/main_nav.html index 1fdfb461c..d9e051222 100644 --- a/app/templates/main_nav.html +++ b/app/templates/main_nav.html @@ -1,9 +1,9 @@ {% from "components/banner.html" import banner_wrapper %} -{% if request.args['help'] and request.args['help'] != '0' %} +{% if help %} {% call banner_wrapper(type='tour') %}

Try this example

-
+

1.

@@ -13,7 +13,7 @@

-
+

2.

@@ -23,7 +23,7 @@

-
+

3.

@@ -31,7 +31,7 @@

Notify delivers the message

- {% if request.args['help'] == '3' %} + {% if help == '3' %} Now go to your dashboard diff --git a/app/templates/partials/jobs/notifications.html b/app/templates/partials/jobs/notifications.html index 1148f8752..506c2007d 100644 --- a/app/templates/partials/jobs/notifications.html +++ b/app/templates/partials/jobs/notifications.html @@ -4,7 +4,7 @@
{% endif %} - {% if notifications and request.args.get('help', '0') == '0' %} + {% if notifications and not help %}

Download as a CSV file   diff --git a/app/templates/views/check.html b/app/templates/views/check.html index 9f3571dad..ab638153b 100644 --- a/app/templates/views/check.html +++ b/app/templates/views/check.html @@ -174,7 +174,7 @@ {% else %}

diff --git a/app/templates/views/send-test.html b/app/templates/views/send-test.html index 980ba2a1b..d564730fc 100644 --- a/app/templates/views/send-test.html +++ b/app/templates/views/send-test.html @@ -55,7 +55,7 @@ {% endcall %} {{ page_footer("Preview", back_link=( - url_for('.choose_template', service_id=current_service.id, template_type=template.template_type)) if not request.args['help'] else None + url_for('.send_messages', service_id=current_service.id, template_id=template.id)) if not help else None ) }} diff --git a/app/utils.py b/app/utils.py index 242af78dc..f3b4edb15 100644 --- a/app/utils.py +++ b/app/utils.py @@ -186,3 +186,7 @@ class Spreadsheet(): file_type=extension, file_content=file_content.getvalue() ).to_array(), filename) + + +def get_help_argument(): + return request.args.get('help') if request.args.get('help') in ('1', '2', '3') else None