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 @@