From 77d49754c638d786944503df4037c1b9de02cd12 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Fri, 23 Aug 2024 11:03:32 -0700 Subject: [PATCH 01/14] initial --- app/main/views/dashboard.py | 19 ++++++++++++++++++- app/templates/views/dashboard/dashboard.html | 3 +++ poetry.lock | 1 - 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/app/main/views/dashboard.py b/app/main/views/dashboard.py index 0913dcfdda..5310c4b220 100644 --- a/app/main/views/dashboard.py +++ b/app/main/views/dashboard.py @@ -3,7 +3,7 @@ from functools import partial from itertools import groupby -from flask import Response, abort, jsonify, render_template, request, session, url_for +from flask import Response, abort, app, jsonify, render_template, request, session, url_for from flask_login import current_user from werkzeug.utils import redirect @@ -21,6 +21,7 @@ DELIVERED_STATUSES, FAILURE_STATUSES, REQUESTED_STATUSES, + hilite, service_has_permission, ) from app.utils.csv import Spreadsheet @@ -281,6 +282,17 @@ def inbox_download(service_id): }, ) +@main.route('/get-timezone', methods=['POST', 'GET']) +def get_timezone(): + print(hilite("ENTER GET-TIMEZONE")) + timezone = request.cookies.get('timezone', 'UTC') + print(hilite(f"TIMEZONE {timezone}")) + #data = request.get_json() + #print(f"HEY DATA WAS {data}") + #timezone = data.get('timezone') + #print(hilite(f"TIMEZONE = {timezone}")) + #session['timezone'] = timezone + return jsonify({'message': f'Timezone get successfully {timezone}'}), 200 def get_inbox_partials(service_id): page = int(request.args.get("page", 1)) @@ -402,6 +414,11 @@ def get_dashboard_partials(service_id): def get_dashboard_totals(statistics): + + timezone = request.cookies.get('timezone', 'UTC') + if current_user.preferred_timezone is not timezone: + current_user.update(preferred_timezone=timezone) + for msg_type in statistics.values(): msg_type["failed_percentage"] = get_formatted_percentage( msg_type["failed"], msg_type["requested"] diff --git a/app/templates/views/dashboard/dashboard.html b/app/templates/views/dashboard/dashboard.html index 2254c3c78f..6bfce7bd01 100644 --- a/app/templates/views/dashboard/dashboard.html +++ b/app/templates/views/dashboard/dashboard.html @@ -1,3 +1,6 @@ + +

{{ session['timezone'] }}

+ {% extends "withnav_template.html" %} {% from "components/table.html" import list_table, field, text_field, link_field, right_aligned_field_heading, hidden_field_heading, row_heading, notification_status_field, notification_carrier_field, notification_carrier_message_field %} diff --git a/poetry.lock b/poetry.lock index ae6ab5bb7c..716e54132e 100644 --- a/poetry.lock +++ b/poetry.lock @@ -2430,7 +2430,6 @@ files = [ {file = "PyYAML-6.0.1-cp311-cp311-win_amd64.whl", hash = "sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34"}, {file = "PyYAML-6.0.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:855fb52b0dc35af121542a76b9a84f8d1cd886ea97c84703eaa6d88e37a2ad28"}, {file = "PyYAML-6.0.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:40df9b996c2b73138957fe23a16a4f0ba614f4c0efce1e9406a184b6d07fa3a9"}, - {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a08c6f0fe150303c1c6b71ebcd7213c2858041a7e01975da3a99aed1e7a378ef"}, {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6c22bec3fbe2524cde73d7ada88f6566758a8f7227bfbf93a408a9d86bcc12a0"}, {file = "PyYAML-6.0.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8d4e9c88387b0f5c7d5f281e55304de64cf7f9c0021a3525bd3b1c542da3b0e4"}, {file = "PyYAML-6.0.1-cp312-cp312-win32.whl", hash = "sha256:d483d2cdf104e7c9fa60c544d92981f12ad66a457afae824d146093b8c294c54"}, From c7b83596bacd4107c67c0a23fc4a287c77331330 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Fri, 23 Aug 2024 11:47:43 -0700 Subject: [PATCH 02/14] add gulp reference --- app/assets/javascripts/setTimezone.js | 4 ++++ app/main/views/dashboard.py | 1 + app/templates/views/dashboard/dashboard.html | 1 - gulpfile.js | 1 + 4 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 app/assets/javascripts/setTimezone.js diff --git a/app/assets/javascripts/setTimezone.js b/app/assets/javascripts/setTimezone.js new file mode 100644 index 0000000000..5a79b0190e --- /dev/null +++ b/app/assets/javascripts/setTimezone.js @@ -0,0 +1,4 @@ +document.addEventListener('DOMContentLoaded', function() { + var timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone; + document.cookie = `timezone=${timeZone}; path=/`; +}) diff --git a/app/main/views/dashboard.py b/app/main/views/dashboard.py index 5310c4b220..545672afb9 100644 --- a/app/main/views/dashboard.py +++ b/app/main/views/dashboard.py @@ -416,6 +416,7 @@ def get_dashboard_partials(service_id): def get_dashboard_totals(statistics): timezone = request.cookies.get('timezone', 'UTC') + print(hilite(f"HURRAY TIMEZONE IS {timezone}")) if current_user.preferred_timezone is not timezone: current_user.update(preferred_timezone=timezone) diff --git a/app/templates/views/dashboard/dashboard.html b/app/templates/views/dashboard/dashboard.html index 6bfce7bd01..12c0df12fa 100644 --- a/app/templates/views/dashboard/dashboard.html +++ b/app/templates/views/dashboard/dashboard.html @@ -1,4 +1,3 @@ -

{{ session['timezone'] }}

{% extends "withnav_template.html" %} diff --git a/gulpfile.js b/gulpfile.js index d4d6ac81f4..22fcbb487f 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -61,6 +61,7 @@ const javascripts = () => { paths.src + 'javascripts/fileUpload.js', paths.src + 'javascripts/radioSelect.js', paths.src + 'javascripts/updateContent.js', + paths.src + 'javascripts/setTimezone.js', paths.src + 'javascripts/listEntry.js', paths.src + 'javascripts/liveSearch.js', paths.src + 'javascripts/errorTracking.js', From 85bafde78d0517c6e56daef56fc1a110b5b3c8a0 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Fri, 23 Aug 2024 12:13:14 -0700 Subject: [PATCH 03/14] fix flake 8 --- app/main/views/dashboard.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/app/main/views/dashboard.py b/app/main/views/dashboard.py index 545672afb9..cc65106c97 100644 --- a/app/main/views/dashboard.py +++ b/app/main/views/dashboard.py @@ -3,7 +3,16 @@ from functools import partial from itertools import groupby -from flask import Response, abort, app, jsonify, render_template, request, session, url_for +from flask import ( + Response, + abort, + app, + jsonify, + render_template, + request, + session, + url_for, +) from flask_login import current_user from werkzeug.utils import redirect @@ -282,17 +291,19 @@ def inbox_download(service_id): }, ) -@main.route('/get-timezone', methods=['POST', 'GET']) + +@main.route("/get-timezone", methods=["POST", "GET"]) def get_timezone(): print(hilite("ENTER GET-TIMEZONE")) - timezone = request.cookies.get('timezone', 'UTC') + timezone = request.cookies.get("timezone", "UTC") print(hilite(f"TIMEZONE {timezone}")) - #data = request.get_json() - #print(f"HEY DATA WAS {data}") - #timezone = data.get('timezone') - #print(hilite(f"TIMEZONE = {timezone}")) - #session['timezone'] = timezone - return jsonify({'message': f'Timezone get successfully {timezone}'}), 200 + # data = request.get_json() + # print(f"HEY DATA WAS {data}") + # timezone = data.get('timezone') + # print(hilite(f"TIMEZONE = {timezone}")) + # session['timezone'] = timezone + return jsonify({"message": f"Timezone get successfully {timezone}"}), 200 + def get_inbox_partials(service_id): page = int(request.args.get("page", 1)) @@ -415,7 +426,7 @@ def get_dashboard_partials(service_id): def get_dashboard_totals(statistics): - timezone = request.cookies.get('timezone', 'UTC') + timezone = request.cookies.get("timezone", "UTC") print(hilite(f"HURRAY TIMEZONE IS {timezone}")) if current_user.preferred_timezone is not timezone: current_user.update(preferred_timezone=timezone) From 50e67d2308a89ae8b102ada7bf05811bde711bd9 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Fri, 23 Aug 2024 12:21:43 -0700 Subject: [PATCH 04/14] cleanup --- app/main/views/dashboard.py | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/app/main/views/dashboard.py b/app/main/views/dashboard.py index cc65106c97..fea3e3ece0 100644 --- a/app/main/views/dashboard.py +++ b/app/main/views/dashboard.py @@ -6,7 +6,7 @@ from flask import ( Response, abort, - app, + current_app, jsonify, render_template, request, @@ -292,19 +292,6 @@ def inbox_download(service_id): ) -@main.route("/get-timezone", methods=["POST", "GET"]) -def get_timezone(): - print(hilite("ENTER GET-TIMEZONE")) - timezone = request.cookies.get("timezone", "UTC") - print(hilite(f"TIMEZONE {timezone}")) - # data = request.get_json() - # print(f"HEY DATA WAS {data}") - # timezone = data.get('timezone') - # print(hilite(f"TIMEZONE = {timezone}")) - # session['timezone'] = timezone - return jsonify({"message": f"Timezone get successfully {timezone}"}), 200 - - def get_inbox_partials(service_id): page = int(request.args.get("page", 1)) inbound_messages_data = service_api_client.get_most_recent_inbound_sms( @@ -425,9 +412,9 @@ def get_dashboard_partials(service_id): def get_dashboard_totals(statistics): - - timezone = request.cookies.get("timezone", "UTC") - print(hilite(f"HURRAY TIMEZONE IS {timezone}")) + # This is set in dashboard.html on page load + timezone = request.cookies.get("timezone", "US/Eastern") + current_app.logger.debug(hilite(f"User's timezone is {timezone}")) if current_user.preferred_timezone is not timezone: current_user.update(preferred_timezone=timezone) From c67407f0907afb1de2d40e70ac463f92b40d2c39 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Fri, 23 Aug 2024 12:59:00 -0700 Subject: [PATCH 05/14] fix some tests --- app/main/views/dashboard.py | 12 ++++++--- app/models/user.py | 1 + tests/app/main/views/test_conversation.py | 26 +++++++++---------- tests/app/main/views/test_dashboard.py | 18 ++++++------- tests/app/main/views/test_jobs.py | 2 +- tests/app/main/views/test_templates.py | 4 +-- .../app/main/views/uploads/test_upload_hub.py | 6 ++--- tests/app/models/test_user.py | 1 + 8 files changed, 38 insertions(+), 32 deletions(-) diff --git a/app/main/views/dashboard.py b/app/main/views/dashboard.py index fea3e3ece0..8e4101a9d3 100644 --- a/app/main/views/dashboard.py +++ b/app/main/views/dashboard.py @@ -413,10 +413,14 @@ def get_dashboard_partials(service_id): def get_dashboard_totals(statistics): # This is set in dashboard.html on page load - timezone = request.cookies.get("timezone", "US/Eastern") - current_app.logger.debug(hilite(f"User's timezone is {timezone}")) - if current_user.preferred_timezone is not timezone: - current_user.update(preferred_timezone=timezone) + try: + timezone = request.cookies.get("timezone", "US/Eastern") + current_app.logger.debug(hilite(f"User's timezone is {timezone}")) + serialized_user = current_user.serialize() + if serialized_user["preferred_timezone"] is not timezone: + current_user.update(preferred_timezone=timezone) + except RuntimeError as e: + current_app.logger.warning("Can't get timezone, running tests?") for msg_type in statistics.values(): msg_type["failed_percentage"] = get_formatted_percentage( diff --git a/app/models/user.py b/app/models/user.py index 3c96fc42c4..6991dc035b 100644 --- a/app/models/user.py +++ b/app/models/user.py @@ -58,6 +58,7 @@ def __init__(self, _dict): super().__init__(_dict) self.permissions = _dict.get("permissions", {}) self._platform_admin = _dict["platform_admin"] + self.preferred_timezone = _dict.get("preferred_timezone", "America/New_York") @classmethod def from_id(cls, user_id): diff --git a/tests/app/main/views/test_conversation.py b/tests/app/main/views/test_conversation.py index 1139cd43f8..15a5ec587c 100644 --- a/tests/app/main/views/test_conversation.py +++ b/tests/app/main/views/test_conversation.py @@ -113,55 +113,55 @@ def test_view_conversation( [ ( "message-8", - "yesterday at 14:59 US/Eastern", + "yesterday at 14:59 America/New_York", ), ( "message-7", - "yesterday at 14:59 US/Eastern", + "yesterday at 14:59 America/New_York", ), ( "message-6", - "yesterday at 16:59 US/Eastern", + "yesterday at 16:59 America/New_York", ), ( "message-5", - "yesterday at 18:59 US/Eastern", + "yesterday at 18:59 America/New_York", ), ( "message-4", - "yesterday at 20:59 US/Eastern", + "yesterday at 20:59 America/New_York", ), ( "message-3", - "yesterday at 22:59 US/Eastern", + "yesterday at 22:59 America/New_York", ), ( "message-2", - "yesterday at 22:59 US/Eastern", + "yesterday at 22:59 America/New_York", ), ( "message-1", - "yesterday at 23:00 US/Eastern", + "yesterday at 23:00 America/New_York", ), ( expected_outbound_content, - "yesterday at 00:00 US/Eastern", + "yesterday at 00:00 America/New_York", ), ( expected_outbound_content, - "yesterday at 00:00 US/Eastern", + "yesterday at 00:00 America/New_York", ), ( expected_outbound_content, - "yesterday at 00:00 US/Eastern", + "yesterday at 00:00 America/New_York", ), ( expected_outbound_content, - "yesterday at 00:00 US/Eastern", + "yesterday at 00:00 America/New_York", ), ( expected_outbound_content, - "yesterday at 00:00 US/Eastern", + "yesterday at 00:00 America/New_York", ), ] ): diff --git a/tests/app/main/views/test_dashboard.py b/tests/app/main/views/test_dashboard.py index d5bab63232..8703adf3a5 100644 --- a/tests/app/main/views/test_dashboard.py +++ b/tests/app/main/views/test_dashboard.py @@ -550,14 +550,14 @@ def test_download_inbox( ) assert response.get_data(as_text=True) == ( "Phone number,Message,Received\r\n" - "(202) 867-5300,message-1,07-01-2016 11:00 US/Eastern\r\n" - "(202) 867-5300,message-2,07-01-2016 10:59 US/Eastern\r\n" - "(202) 867-5300,message-3,07-01-2016 10:59 US/Eastern\r\n" - "(202) 867-5302,message-4,07-01-2016 08:59 US/Eastern\r\n" - "+33(0)1 12345678,message-5,07-01-2016 06:59 US/Eastern\r\n" - "(202) 555-0104,message-6,07-01-2016 04:59 US/Eastern\r\n" - "(202) 555-0104,message-7,07-01-2016 02:59 US/Eastern\r\n" - "+68212345,message-8,07-01-2016 02:59 US/Eastern\r\n" + "(202) 867-5300,message-1,07-01-2016 11:00 America/New_York\r\n" + "(202) 867-5300,message-2,07-01-2016 10:59 America/New_York\r\n" + "(202) 867-5300,message-3,07-01-2016 10:59 America/New_York\r\n" + "(202) 867-5302,message-4,07-01-2016 08:59 America/New_York\r\n" + "+33(0)1 12345678,message-5,07-01-2016 06:59 America/New_York\r\n" + "(202) 555-0104,message-6,07-01-2016 04:59 America/New_York\r\n" + "(202) 555-0104,message-7,07-01-2016 02:59 America/New_York\r\n" + "+68212345,message-8,07-01-2016 02:59 America/New_York\r\n" ) @@ -849,7 +849,7 @@ def test_should_show_upcoming_jobs_on_dashboard( assert normalize_spaces(page.select_one("main h2").text) == ("In the next few days") assert normalize_spaces(page.select_one("a.banner-dashboard").text) == ( - "2 files waiting to send " "- sending starts today at 06:09 US/Eastern" + "2 files waiting to send " "- sending starts today at 06:09 America/New_York" ) assert page.select_one("a.banner-dashboard")["href"] == url_for( diff --git a/tests/app/main/views/test_jobs.py b/tests/app/main/views/test_jobs.py index c4a7561946..ab09f7ecd8 100644 --- a/tests/app/main/views/test_jobs.py +++ b/tests/app/main/views/test_jobs.py @@ -349,7 +349,7 @@ def test_should_show_scheduled_job( ) assert normalize_spaces(page.select("main div p")[1].text) == ( - "Example template - service one was scheduled on January 02, 2016 at 12:00 AM US/Eastern by Test User" + "Example template - service one was scheduled on January 02, 2016 at 12:00 AM America/New_York by Test User" ) assert page.select("main p a")[0]["href"] == url_for( diff --git a/tests/app/main/views/test_templates.py b/tests/app/main/views/test_templates.py index b23caf925b..6e2ff227de 100644 --- a/tests/app/main/views/test_templates.py +++ b/tests/app/main/views/test_templates.py @@ -497,7 +497,7 @@ def test_caseworker_sees_template_page_if_template_is_deleted( ) assert ( page.select("p.hint")[0].text.strip() - == "This template was deleted today at 15:00 US/Eastern." + == "This template was deleted today at 15:00 America/New_York." ) mock_get_deleted_template.assert_called_with(SERVICE_ONE_ID, template_id, None) @@ -1591,7 +1591,7 @@ def test_should_show_page_for_a_deleted_template( ) assert ( page.select("p.hint")[0].text.strip() - == "This template was deleted today at 15:00 US/Eastern." + == "This template was deleted today at 15:00 America/New_York." ) assert "Delete this template" not in page.select_one("main").text diff --git a/tests/app/main/views/uploads/test_upload_hub.py b/tests/app/main/views/uploads/test_upload_hub.py index ee24fba653..53ba1f161a 100644 --- a/tests/app/main/views/uploads/test_upload_hub.py +++ b/tests/app/main/views/uploads/test_upload_hub.py @@ -52,7 +52,7 @@ def test_get_upload_hub_page( assert normalize_spaces(uploads[0].text.strip()) == ( "some.csv " - "Sent 1 January 2016 at 06:09 US/Eastern " + "Sent 1 January 2016 at 06:09 America/New_York " "0 pending 8 delivered 2 failed" ) assert uploads[0].select_one("a.file-list-filename-large")["href"] == ( @@ -82,12 +82,12 @@ def test_uploads_page_shows_scheduled_jobs( ("File Status"), ( "even_later.csv " - "Sending 1 January 2016 at 18:09 US/Eastern " + "Sending 1 January 2016 at 18:09 America/New_York " "1 text message waiting to send" ), ( "send_me_later.csv " - "Sending 1 January 2016 at 06:09 US/Eastern " + "Sending 1 January 2016 at 06:09 America/New_York " "1 text message waiting to send" ), ] diff --git a/tests/app/models/test_user.py b/tests/app/models/test_user.py index 1caf85f4a5..099cab14d0 100644 --- a/tests/app/models/test_user.py +++ b/tests/app/models/test_user.py @@ -18,6 +18,7 @@ def test_user(notify_admin): "email_address": "test@user.gsa.gov", "mobile_number": "+12021231234", "state": "pending", + "preferred_timezone": "America/Chicago", "failed_login_count": 0, "platform_admin": False, } From 8e3cd6324fb9f476b0ce0ac68ec00c8d18605baa Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Fri, 23 Aug 2024 13:13:24 -0700 Subject: [PATCH 06/14] fix some tests --- app/main/views/dashboard.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/main/views/dashboard.py b/app/main/views/dashboard.py index 8e4101a9d3..519f46c62f 100644 --- a/app/main/views/dashboard.py +++ b/app/main/views/dashboard.py @@ -420,7 +420,7 @@ def get_dashboard_totals(statistics): if serialized_user["preferred_timezone"] is not timezone: current_user.update(preferred_timezone=timezone) except RuntimeError as e: - current_app.logger.warning("Can't get timezone, running tests?") + current_app.logger.warning(f"Can't get timezone, running tests? {e}") for msg_type in statistics.values(): msg_type["failed_percentage"] = get_formatted_percentage( From 3456bb47a1e2c6b73b98dc5d4bf0d4ebe04b91dd Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Fri, 23 Aug 2024 14:01:51 -0700 Subject: [PATCH 07/14] move file around --- app/assets/{javascripts => js}/setTimezone.js | 0 app/templates/views/dashboard/dashboard.html | 3 ++- gulpfile.js | 10 ++++++++-- tests/app/main/views/test_dashboard.py | 8 +++++++- 4 files changed, 17 insertions(+), 4 deletions(-) rename app/assets/{javascripts => js}/setTimezone.js (100%) diff --git a/app/assets/javascripts/setTimezone.js b/app/assets/js/setTimezone.js similarity index 100% rename from app/assets/javascripts/setTimezone.js rename to app/assets/js/setTimezone.js diff --git a/app/templates/views/dashboard/dashboard.html b/app/templates/views/dashboard/dashboard.html index 12c0df12fa..87299de133 100644 --- a/app/templates/views/dashboard/dashboard.html +++ b/app/templates/views/dashboard/dashboard.html @@ -1,4 +1,4 @@ -

{{ session['timezone'] }}

+ {% extends "withnav_template.html" %} @@ -141,3 +141,4 @@

Service activity

{% endblock %} + diff --git a/gulpfile.js b/gulpfile.js index 22fcbb487f..4d2571eaec 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -61,7 +61,6 @@ const javascripts = () => { paths.src + 'javascripts/fileUpload.js', paths.src + 'javascripts/radioSelect.js', paths.src + 'javascripts/updateContent.js', - paths.src + 'javascripts/setTimezone.js', paths.src + 'javascripts/listEntry.js', paths.src + 'javascripts/liveSearch.js', paths.src + 'javascripts/errorTracking.js', @@ -98,6 +97,13 @@ const copyGtmHead = () => { .pipe(dest(paths.dist + 'js/')); }; +// Task to copy `setTimezone.js` +const copySetTimezone = () => { + return src(paths.src + 'js/setTimezone.js') + .pipe(dest(paths.dist + 'js/')); +}; + + // Task to copy images const copyImages = () => { return src(paths.src + 'images/**/*', { encoding: false }) @@ -123,4 +129,4 @@ const copyAssets = async () => { await uswds.copyAssets(); }; -exports.default = series(styles, javascripts, copyGtmHead, copyImages, copyAssets); +exports.default = series(styles, javascripts, copyGtmHead, copySetTimezone, copyImages, copyAssets); diff --git a/tests/app/main/views/test_dashboard.py b/tests/app/main/views/test_dashboard.py index 8703adf3a5..c04c578f4d 100644 --- a/tests/app/main/views/test_dashboard.py +++ b/tests/app/main/views/test_dashboard.py @@ -1757,11 +1757,13 @@ def test_org_breadcrumbs_show_if_user_is_platform_admin( platform_admin_user, client_request, ): + print("ENTER TESET") service_one_json = service_json( SERVICE_ONE_ID, users=[platform_admin_user["id"]], organization_id=ORGANISATION_ID, ) + print("GOT SERVICE ONE") mocker.patch( "app.service_api_client.get_service", return_value={"data": service_one_json} @@ -1783,10 +1785,14 @@ def test_org_breadcrumbs_show_if_user_is_platform_admin( "app.main.views.dashboard.get_daily_stats_by_user", return_value=mock_daily_stats_by_user, ) + print("DID ALL PATCHES") client_request.login(platform_admin_user, service_one_json) + print("LOGGED IN") page = client_request.get("main.service_dashboard", service_id=SERVICE_ONE_ID) - + print("HERE IS THE PAGE") + print(page) + print("XXXXXXXXXXXXXXXXX") assert page.select_one(".navigation-organization-link")["href"] == url_for( "main.organization_dashboard", org_id=ORGANISATION_ID, From 0c612581cdf8b2be388e3110c9b4866fe70a6f54 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Mon, 26 Aug 2024 07:50:24 -0700 Subject: [PATCH 08/14] finish up --- app/main/views/dashboard.py | 28 +++++++++++++------- app/templates/views/dashboard/dashboard.html | 5 +++- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/app/main/views/dashboard.py b/app/main/views/dashboard.py index 519f46c62f..8e603f86de 100644 --- a/app/main/views/dashboard.py +++ b/app/main/views/dashboard.py @@ -49,6 +49,7 @@ def old_service_dashboard(service_id): @main.route("/services/") @user_has_permissions() def service_dashboard(service_id): + if session.get("invited_user_id"): session.pop("invited_user_id", None) session["service_id"] = service_id @@ -412,21 +413,13 @@ def get_dashboard_partials(service_id): def get_dashboard_totals(statistics): - # This is set in dashboard.html on page load - try: - timezone = request.cookies.get("timezone", "US/Eastern") - current_app.logger.debug(hilite(f"User's timezone is {timezone}")) - serialized_user = current_user.serialize() - if serialized_user["preferred_timezone"] is not timezone: - current_user.update(preferred_timezone=timezone) - except RuntimeError as e: - current_app.logger.warning(f"Can't get timezone, running tests? {e}") for msg_type in statistics.values(): msg_type["failed_percentage"] = get_formatted_percentage( msg_type["failed"], msg_type["requested"] ) msg_type["show_warning"] = float(msg_type["failed_percentage"]) > 3 + return statistics @@ -485,6 +478,8 @@ def get_months_for_financial_year(year, time_format="%B"): def get_current_month_for_financial_year(year): + # Setting the timezone here because we need to set it somewhere. + set_timezone() current_month = datetime.now().month return current_month @@ -557,3 +552,18 @@ def get_tuples_of_financial_years( ) for year in reversed(range(start, end + 1)) ) + + +def set_timezone(): + # This is set in dashboard.html on page load + print(hilite("INVOKING set_timezone()!!!!")) + try: + timezone = request.cookies.get("timezone", "US/Eastern") + current_app.logger.debug(hilite(f"User's timezone is {timezone}")) + serialized_user = current_user.serialize() + if serialized_user["preferred_timezone"] is not timezone: + current_user.update(preferred_timezone=timezone) + except RuntimeError as e: + current_app.logger.exception(hilite(f"Can't get timezone, running tests?")) + except Exception as e: + current_app.logger.exception(hilite(f"Can't get timezone, running tests?")) diff --git a/app/templates/views/dashboard/dashboard.html b/app/templates/views/dashboard/dashboard.html index 87299de133..7126e7ca84 100644 --- a/app/templates/views/dashboard/dashboard.html +++ b/app/templates/views/dashboard/dashboard.html @@ -7,6 +7,10 @@ {% block service_page_title %} Dashboard + + + + {% endblock %} {% block maincolumn_content %} @@ -141,4 +145,3 @@

Service activity

{% endblock %} - From f78fe350b05c3cfd38c5cac7dd69f38257ee9727 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Mon, 26 Aug 2024 07:59:39 -0700 Subject: [PATCH 09/14] fix flake 8 --- app/main/views/dashboard.py | 9 +++------ tests/app/main/views/test_dashboard.py | 7 ------- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/app/main/views/dashboard.py b/app/main/views/dashboard.py index 8e603f86de..2a7b3e76ee 100644 --- a/app/main/views/dashboard.py +++ b/app/main/views/dashboard.py @@ -555,15 +555,12 @@ def get_tuples_of_financial_years( def set_timezone(): - # This is set in dashboard.html on page load - print(hilite("INVOKING set_timezone()!!!!")) + # Cookie is set in dashboard.html on page load try: timezone = request.cookies.get("timezone", "US/Eastern") current_app.logger.debug(hilite(f"User's timezone is {timezone}")) serialized_user = current_user.serialize() if serialized_user["preferred_timezone"] is not timezone: current_user.update(preferred_timezone=timezone) - except RuntimeError as e: - current_app.logger.exception(hilite(f"Can't get timezone, running tests?")) - except Exception as e: - current_app.logger.exception(hilite(f"Can't get timezone, running tests?")) + except Exception: + current_app.logger.exception(hilite("Can't get timezone")) diff --git a/tests/app/main/views/test_dashboard.py b/tests/app/main/views/test_dashboard.py index c04c578f4d..e2a7a6b587 100644 --- a/tests/app/main/views/test_dashboard.py +++ b/tests/app/main/views/test_dashboard.py @@ -1757,13 +1757,11 @@ def test_org_breadcrumbs_show_if_user_is_platform_admin( platform_admin_user, client_request, ): - print("ENTER TESET") service_one_json = service_json( SERVICE_ONE_ID, users=[platform_admin_user["id"]], organization_id=ORGANISATION_ID, ) - print("GOT SERVICE ONE") mocker.patch( "app.service_api_client.get_service", return_value={"data": service_one_json} @@ -1785,14 +1783,9 @@ def test_org_breadcrumbs_show_if_user_is_platform_admin( "app.main.views.dashboard.get_daily_stats_by_user", return_value=mock_daily_stats_by_user, ) - print("DID ALL PATCHES") client_request.login(platform_admin_user, service_one_json) - print("LOGGED IN") page = client_request.get("main.service_dashboard", service_id=SERVICE_ONE_ID) - print("HERE IS THE PAGE") - print(page) - print("XXXXXXXXXXXXXXXXX") assert page.select_one(".navigation-organization-link")["href"] == url_for( "main.organization_dashboard", org_id=ORGANISATION_ID, From 7b6b363532cfbf6197ad199fe27dea4f6349c1c0 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Mon, 26 Aug 2024 09:02:39 -0700 Subject: [PATCH 10/14] add a call on the send page as well --- app/main/views/dashboard.py | 13 +------------ app/main/views/send.py | 2 ++ app/main/views/user_profile.py | 12 ++++++++++++ app/templates/views/send.html | 1 + 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/app/main/views/dashboard.py b/app/main/views/dashboard.py index 2a7b3e76ee..213624329d 100644 --- a/app/main/views/dashboard.py +++ b/app/main/views/dashboard.py @@ -25,6 +25,7 @@ ) from app.formatters import format_date_numeric, format_datetime_numeric, get_time_left from app.main import main +from app.main.views.user_profile import set_timezone from app.statistics_utils import get_formatted_percentage from app.utils import ( DELIVERED_STATUSES, @@ -552,15 +553,3 @@ def get_tuples_of_financial_years( ) for year in reversed(range(start, end + 1)) ) - - -def set_timezone(): - # Cookie is set in dashboard.html on page load - try: - timezone = request.cookies.get("timezone", "US/Eastern") - current_app.logger.debug(hilite(f"User's timezone is {timezone}")) - serialized_user = current_user.serialize() - if serialized_user["preferred_timezone"] is not timezone: - current_user.update(preferred_timezone=timezone) - except Exception: - current_app.logger.exception(hilite("Can't get timezone")) diff --git a/app/main/views/send.py b/app/main/views/send.py index 6f2817826f..e6843da18d 100644 --- a/app/main/views/send.py +++ b/app/main/views/send.py @@ -33,6 +33,7 @@ SetSenderForm, get_placeholder_form_instance, ) +from app.main.views.user_profile import set_timezone from app.models.user import Users from app.s3_client.s3_csv_client import ( get_csv_metadata, @@ -1075,6 +1076,7 @@ def get_spreadsheet_column_headings_from_template(template): def get_recipient(): + set_timezone() if {"recipient", "placeholders"} - set(session.keys()): return None diff --git a/app/main/views/user_profile.py b/app/main/views/user_profile.py index 2efac8b236..bec6268b52 100644 --- a/app/main/views/user_profile.py +++ b/app/main/views/user_profile.py @@ -275,3 +275,15 @@ def user_profile_disable_platform_admin_view(): return render_template( "views/user-profile/disable-platform-admin-view.html", form=form ) + + +def set_timezone(): + # Cookie is set in dashboard.html on page load + try: + timezone = request.cookies.get("timezone", "US/Eastern") + current_app.logger.debug(f"User's timezone is {timezone}") + serialized_user = current_user.serialize() + if serialized_user["preferred_timezone"] is not timezone: + current_user.update(preferred_timezone=timezone) + except Exception: + current_app.logger.exception(hilite("Can't get timezone")) diff --git a/app/templates/views/send.html b/app/templates/views/send.html index 8685f81968..b8a0c65610 100644 --- a/app/templates/views/send.html +++ b/app/templates/views/send.html @@ -4,6 +4,7 @@ {% from "components/file-upload.html" import file_upload %} {% from "components/table.html" import list_table, text_field, index_field, index_field_heading %} {% from "components/components/back-link/macro.njk" import usaBackLink %} + {% block service_page_title %} Upload a list of {{ 999|recipient_count_label(template.template_type) }} From 9907409efd2fe6c8203e7b5bb6ef8916e143acec Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Mon, 26 Aug 2024 10:06:29 -0700 Subject: [PATCH 11/14] remove Change button for timezone --- app/templates/views/user-profile.html | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/app/templates/views/user-profile.html b/app/templates/views/user-profile.html index a03eeab508..fa6b069c2b 100644 --- a/app/templates/views/user-profile.html +++ b/app/templates/views/user-profile.html @@ -45,14 +45,9 @@

User profile

{% endcall %} {% call row() %} - {{ text_field('Preferred Timezone') }} + {{ text_field('Preferred timezone') }} {{ optional_text_field(current_user.preferred_timezone) }} - {{ edit_field( - 'Change', - url_for('.user_profile_preferred_timezone'), - suffix='preferred timezone' - ) - }} + {{ text_field('Set automatically') }} {% endcall %} {% if current_user.platform_admin or session.get('disable_platform_admin_view') %} From e15c89703beea15c25788c6eae8c9f25048da01f Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Mon, 26 Aug 2024 10:24:29 -0700 Subject: [PATCH 12/14] fix flake 8 --- app/main/views/dashboard.py | 2 -- app/main/views/user_profile.py | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/main/views/dashboard.py b/app/main/views/dashboard.py index 213624329d..c9815e5fc7 100644 --- a/app/main/views/dashboard.py +++ b/app/main/views/dashboard.py @@ -6,7 +6,6 @@ from flask import ( Response, abort, - current_app, jsonify, render_template, request, @@ -31,7 +30,6 @@ DELIVERED_STATUSES, FAILURE_STATUSES, REQUESTED_STATUSES, - hilite, service_has_permission, ) from app.utils.csv import Spreadsheet diff --git a/app/main/views/user_profile.py b/app/main/views/user_profile.py index bec6268b52..e4ab1f2dba 100644 --- a/app/main/views/user_profile.py +++ b/app/main/views/user_profile.py @@ -10,6 +10,7 @@ session, url_for, ) +from app.utils import hilite from flask_login import current_user from app import user_api_client From 407f049360e99dcbd46d100af92ad8880afbdfbe Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Mon, 26 Aug 2024 11:11:59 -0700 Subject: [PATCH 13/14] fix sort ugh --- app/main/views/dashboard.py | 10 +--------- app/main/views/user_profile.py | 2 +- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/app/main/views/dashboard.py b/app/main/views/dashboard.py index c9815e5fc7..ee289c3e5d 100644 --- a/app/main/views/dashboard.py +++ b/app/main/views/dashboard.py @@ -3,15 +3,7 @@ from functools import partial from itertools import groupby -from flask import ( - Response, - abort, - jsonify, - render_template, - request, - session, - url_for, -) +from flask import Response, abort, jsonify, render_template, request, session, url_for from flask_login import current_user from werkzeug.utils import redirect diff --git a/app/main/views/user_profile.py b/app/main/views/user_profile.py index e4ab1f2dba..372fa62135 100644 --- a/app/main/views/user_profile.py +++ b/app/main/views/user_profile.py @@ -10,7 +10,6 @@ session, url_for, ) -from app.utils import hilite from flask_login import current_user from app import user_api_client @@ -30,6 +29,7 @@ TwoFactorForm, ) from app.models.user import User +from app.utils import hilite from app.utils.user import user_is_gov_user, user_is_logged_in from notifications_utils.url_safe_token import check_token From d756b2289f63784fd10bab0e3733d8f93d905a34 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Tue, 27 Aug 2024 12:47:15 -0700 Subject: [PATCH 14/14] code review feedback --- app/main/views/user_profile.py | 2 +- app/templates/views/dashboard/dashboard.html | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/app/main/views/user_profile.py b/app/main/views/user_profile.py index 372fa62135..ec9e27035f 100644 --- a/app/main/views/user_profile.py +++ b/app/main/views/user_profile.py @@ -282,7 +282,7 @@ def set_timezone(): # Cookie is set in dashboard.html on page load try: timezone = request.cookies.get("timezone", "US/Eastern") - current_app.logger.debug(f"User's timezone is {timezone}") + current_app.logger.debug(hilite(f"User's timezone is {timezone}")) serialized_user = current_user.serialize() if serialized_user["preferred_timezone"] is not timezone: current_user.update(preferred_timezone=timezone) diff --git a/app/templates/views/dashboard/dashboard.html b/app/templates/views/dashboard/dashboard.html index 7126e7ca84..27f9a8b715 100644 --- a/app/templates/views/dashboard/dashboard.html +++ b/app/templates/views/dashboard/dashboard.html @@ -7,13 +7,11 @@ {% block service_page_title %} Dashboard - - - - {% endblock %} {% block maincolumn_content %} + +