From fbf0fb1f0d08fe30a4dbb00e85bc504ba54155c5 Mon Sep 17 00:00:00 2001 From: Jonathan Bobel Date: Mon, 17 Mar 2025 16:47:45 -0400 Subject: [PATCH] 2042 - Updates to the error message regarding special characters --- app/main/views/templates.py | 30 ++++++++++++---------- app/templates/views/edit-sms-template.html | 6 ++--- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/app/main/views/templates.py b/app/main/views/templates.py index 5c59e1e7c..e51d2ae53 100644 --- a/app/main/views/templates.py +++ b/app/main/views/templates.py @@ -687,34 +687,36 @@ def _is_latin1(s): 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." + s1 = f"Templates won't save with these characters ™ ∞ • – ≠ “ ‘ … ≤ ≥ or any emoji present. " + s2 = "
The errors they create lead to texts displaying incorrectly on older mobile phones." warning = "" try: _is_latin1(template.content) except UnicodeEncodeError: - warning = f"{s1}{s2}{s3}" + warning = f"{s1}{s2}" + # If message is too long, return the length error if template.is_message_too_long(): return True, ( f"You have " f"{character_count(template.content_count_without_prefix - SMS_CHAR_COUNT_LIMIT)} " f"too many" ) + + # If there's a warning, return it alone and hide the "Will be charged as..." text + if warning: + return True, Markup(warning) + + # Otherwise, show the message count as usual if template.placeholders: - return False, ( - Markup( - f"Will be charged as {message_count(template.fragment_count, template.template_type)} " - f"(not including personalization). {warning}" - ) - ) - return False, ( - # 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} " + return False, Markup( + f"Will be charged as {message_count(template.fragment_count, template.template_type)} " + f"(not including personalization)." ) + + return False, Markup( + f"Will be charged as {message_count(template.fragment_count, template.template_type)}." ) diff --git a/app/templates/views/edit-sms-template.html b/app/templates/views/edit-sms-template.html index 8ef41bdb2..fdc15af5d 100644 --- a/app/templates/views/edit-sms-template.html +++ b/app/templates/views/edit-sms-template.html @@ -28,7 +28,7 @@ {% endif %} {% call form_wrapper() %} -
+
{{ form.name(param_extensions={ "extra_form_group_classes": "margin-bottom-2", @@ -61,12 +61,12 @@
-
+
{{ page_footer('Save') }}
-

+

After saving, you'll have the option to send.