mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-07 18:38:26 -04:00
Merge branch 'main' of https://github.com/GSA/notifications-admin into notify-871
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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"<html><body>Use of characters outside the <a href='{url}'>IEC_8859-1</a> 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.</body></html>"
|
||||
|
||||
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} "
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user