diff --git a/app/main/forms.py b/app/main/forms.py index 5e926dce4..d42d22322 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -1279,6 +1279,23 @@ class ChangeNameForm(StripWhitespaceForm): new_name = GovukTextInputField("Your name") +class ChangePreferredTimezoneForm(StripWhitespaceForm): + def __init__(self, *args, **kwargs): + super(ChangePreferredTimezoneForm, self).__init__(*args, **kwargs) + self.new_preferred_timezone.choices = [ + ("US/Eastern", "US/Eastern"), + ("US/Central", "US/Central"), + ("US/Mountain", "US/Mountain"), + ("US/Pacific", "US/Pacific"), + ("US/Hawaii", "US/Hawaii"), + ] + + new_preferred_timezone = GovukRadiosField( + "What timezone would you like to use?", + default="US/Eastern", + ) + + class ChangeEmailForm(StripWhitespaceForm): def __init__(self, validate_email_func, *args, **kwargs): self.validate_email_func = validate_email_func diff --git a/app/main/views/templates.py b/app/main/views/templates.py index 87f32b60f..e9e5f5b61 100644 --- a/app/main/views/templates.py +++ b/app/main/views/templates.py @@ -2,6 +2,7 @@ from functools import partial from flask import abort, flash, jsonify, redirect, render_template, request, url_for from flask_login import current_user +from markupsafe import Markup from notifications_python_client.errors import HTTPError from notifications_utils import SMS_CHAR_COUNT_LIMIT @@ -679,8 +680,23 @@ def count_content_length(service_id, template_type): ) +def _is_latin1(s): + return bool(s.encode(encoding="latin-1", errors="strict")) + + def _get_content_count_error_and_message_for_template(template): + url = "https://en.wikipedia.org/wiki/ISO/IEC_8859-1" if template.template_type == "sms": + s1 = f"Use of characters outside the IEC_8859-1 character set may increase " + s2 = "the message fragment count, resulting in additional charges, and these IEC_8859-1 " + s3 = "characters may not display properly on some older mobile devices." + + warning = "" + try: + _is_latin1(template.content) + except UnicodeEncodeError: + warning = f"{s1}{s2}{s3}" + if template.is_message_too_long(): return True, ( f"You have " @@ -689,11 +705,16 @@ def _get_content_count_error_and_message_for_template(template): ) if template.placeholders: return False, ( - f"Will be charged as {message_count(template.fragment_count, template.template_type)} " - f"(not including personalization)" + Markup( + f"Will be charged as {message_count(template.fragment_count, template.template_type)} " + f"(not including personalization). {warning}" + ) ) return False, ( - f"Will be charged as {message_count(template.fragment_count, template.template_type)} " + # Markup marks html contents safe so that they render properly. Don't use it if there is user input. + Markup( + f"Will be charged as {message_count(template.fragment_count, template.template_type)}. {warning} " + ) ) diff --git a/app/main/views/user_profile.py b/app/main/views/user_profile.py index 9bd844254..5d10fbf75 100644 --- a/app/main/views/user_profile.py +++ b/app/main/views/user_profile.py @@ -24,6 +24,7 @@ from app.main.forms import ( ChangeMobileNumberForm, ChangeNameForm, ChangePasswordForm, + ChangePreferredTimezoneForm, ConfirmPasswordForm, ServiceOnOffSettingForm, TwoFactorForm, @@ -61,6 +62,22 @@ def user_profile_name(): ) +@main.route("/user-profile/preferred_timezone", methods=["GET", "POST"]) +@user_is_logged_in +def user_profile_preferred_timezone(): + form = ChangePreferredTimezoneForm(new_name=current_user.preferred_timezone) + + if form.validate_on_submit(): + current_user.update(preferred_timezone=form.new_preferred_timezone.data) + current_user.preferred_timezone = form.new_preferred_timezone.data + return redirect(url_for(".user_profile")) + return render_template( + "views/user-profile/change.html", + thing="preferred timezone", + form_field=form.new_preferred_timezone, + ) + + @main.route("/user-profile/email", methods=["GET", "POST"]) @user_is_logged_in @user_is_gov_user diff --git a/app/models/user.py b/app/models/user.py index abd887a4d..7e9f10632 100644 --- a/app/models/user.py +++ b/app/models/user.py @@ -54,7 +54,6 @@ class User(JSONModel, UserMixin): super().__init__(_dict) self.permissions = _dict.get("permissions", {}) self._platform_admin = _dict["platform_admin"] - self.preferred_timezone = "US/Eastern" @classmethod def from_id(cls, user_id): @@ -366,6 +365,7 @@ class User(JSONModel, UserMixin): "permissions": [x for x in self._permissions], "organizations": self.organization_ids, "current_session_id": self.current_session_id, + "preferred_timezone": self.preferred_timezone, } if hasattr(self, "_password"): dct["password"] = self._password diff --git a/app/navigation.py b/app/navigation.py index b96750dc9..99e88fdb4 100644 --- a/app/navigation.py +++ b/app/navigation.py @@ -157,6 +157,7 @@ class HeaderNavigation(Navigation): "user_profile_mobile_number_delete", "user_profile_name", "user_profile_password", + "user_profile_preferred_timezone", "user_profile_disable_platform_admin_view", }, "platform-admin": { diff --git a/app/notify_client/user_api_client.py b/app/notify_client/user_api_client.py index 542d1e96b..bfe2f7182 100644 --- a/app/notify_client/user_api_client.py +++ b/app/notify_client/user_api_client.py @@ -12,6 +12,7 @@ ALLOWED_ATTRIBUTES = { "updated_by", "current_session_id", "email_access_validated_at", + "preferred_timezone", } diff --git a/app/templates/views/edit-sms-template.html b/app/templates/views/edit-sms-template.html index b3f1da603..47ddb2379 100644 --- a/app/templates/views/edit-sms-template.html +++ b/app/templates/views/edit-sms-template.html @@ -50,7 +50,7 @@
-
+
@@ -69,7 +69,7 @@

- +

How to customize your message

diff --git a/app/templates/views/service-settings.html b/app/templates/views/service-settings.html index c3e0803ab..a1dd3232e 100644 --- a/app/templates/views/service-settings.html +++ b/app/templates/views/service-settings.html @@ -219,7 +219,7 @@

You can send up to {{ "{:,}".format(current_service.message_limit) }} messages - per day. + per year.

Problems or comments? diff --git a/app/templates/views/templates/copy.html b/app/templates/views/templates/copy.html index f89d2141d..086936b7a 100644 --- a/app/templates/views/templates/copy.html +++ b/app/templates/views/templates/copy.html @@ -11,7 +11,7 @@ {% block maincolumn_content %}

-

{{ page_title }}

+

{{ page_title }}

{{ copy_folder_path(template_folder_path, current_service.id, from_service, current_user) }}
{% if not services_templates_and_folders.templates_to_show %} @@ -28,32 +28,24 @@