2042 - Updates to the error message regarding special characters

This commit is contained in:
Jonathan Bobel
2025-03-17 16:47:45 -04:00
parent f820ae86f3
commit fbf0fb1f0d
2 changed files with 19 additions and 17 deletions

View File

@@ -687,34 +687,36 @@ def _is_latin1(s):
def _get_content_count_error_and_message_for_template(template): def _get_content_count_error_and_message_for_template(template):
url = "https://en.wikipedia.org/wiki/ISO/IEC_8859-1" url = "https://en.wikipedia.org/wiki/ISO/IEC_8859-1"
if template.template_type == "sms": 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 " s1 = f"<html><body>Templates won't save with these characters ™ ∞ • ≠ “ … ≤ ≥ or any emoji present. "
s2 = "the message fragment count, resulting in additional charges, and these IEC_8859-1 " s2 = "<br>The errors they create lead to texts displaying incorrectly on older mobile phones.</body></html>"
s3 = "characters may not display properly on some older mobile devices.</body></html>"
warning = "" warning = ""
try: try:
_is_latin1(template.content) _is_latin1(template.content)
except UnicodeEncodeError: 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(): if template.is_message_too_long():
return True, ( return True, (
f"You have " f"You have "
f"{character_count(template.content_count_without_prefix - SMS_CHAR_COUNT_LIMIT)} " f"{character_count(template.content_count_without_prefix - SMS_CHAR_COUNT_LIMIT)} "
f"too many" 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: if template.placeholders:
return False, ( return False, Markup(
Markup( f"Will be charged as {message_count(template.fragment_count, template.template_type)} "
f"Will be charged as {message_count(template.fragment_count, template.template_type)} " f"(not including personalization)."
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)}."
) )

View File

@@ -28,7 +28,7 @@
{% endif %} {% endif %}
{% call form_wrapper() %} {% call form_wrapper() %}
<div class="grid-row"> <div class="grid-container padding-0">
<div class="tablet:grid-col-9 mobile-lg:grid-col-12"> <div class="tablet:grid-col-9 mobile-lg:grid-col-12">
{{ form.name(param_extensions={ {{ form.name(param_extensions={
"extra_form_group_classes": "margin-bottom-2", "extra_form_group_classes": "margin-bottom-2",
@@ -61,12 +61,12 @@
</div> </div>
</div> </div>
</div> </div>
<div class="grid-row width-full"> <div class="grid-row width-mobile-lg">
<div class="tablet:grid-col-2 mobile-lg:grid-col-12"> <div class="tablet:grid-col-2 mobile-lg:grid-col-12">
{{ page_footer('Save') }} {{ page_footer('Save') }}
</div> </div>
<div class="tablet:grid-col-10 mobile-lg:grid-col-12"> <div class="tablet:grid-col-10 mobile-lg:grid-col-12">
<p class="usa-hint margin-top-5 tablet:margin-left-neg-2"> <p class="usa-hint margin-top-5 tablet:margin-left-2">
After saving, you'll have the option to send. After saving, you'll have the option to send.
</p> </p>
</div> </div>