mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-13 09:50:08 -04:00
Updates to text area validation on template edit page
This commit is contained in:
@@ -108,32 +108,17 @@ class OnlySMSCharacters:
|
||||
)
|
||||
if non_sms_characters:
|
||||
raise ValidationError(
|
||||
"You cannot use {} in {}. {} will not show up properly on everyone’s phones.".format(
|
||||
"Please remove the unaccepted character {} in your message, then save again".format(
|
||||
formatted_list(
|
||||
non_sms_characters,
|
||||
conjunction="or",
|
||||
conjunction="and",
|
||||
before_each="",
|
||||
after_each="",
|
||||
),
|
||||
{
|
||||
"sms": "text messages",
|
||||
}.get(self._template_type),
|
||||
("It" if len(non_sms_characters) == 1 else "They"),
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
# class NoPlaceholders:
|
||||
|
||||
# def __init__(self, message=None):
|
||||
# self.message = message or (
|
||||
# 'You can’t use ((double brackets)) to personalize this message'
|
||||
# )
|
||||
|
||||
# def __call__(self, form, field):
|
||||
# if Field(field.data).placeholders:
|
||||
# raise ValidationError(self.message)
|
||||
|
||||
|
||||
class LettersNumbersSingleQuotesFullStopsAndUnderscoresOnly:
|
||||
regex = re.compile(r"^[a-zA-Z0-9\s\._']+$")
|
||||
|
||||
@@ -680,19 +680,20 @@ 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):
|
||||
if template.template_type == "sms":
|
||||
s1 = "<html><body>Templates won't save with these characters ™ ∞ • – ≠ “ ‘ … ≤ ≥ or any emoji present. "
|
||||
s2 = "<br>The errors they create lead to texts displaying incorrectly on older mobile phones.</body></html>"
|
||||
s1 = "<html><body>Looks like your template may have one of these characters • ™ ∞ ≤ or ≥ or emoji, which won't save."
|
||||
s2 = "<br>Please remove any unaccepted characters or emojis and try again.</body></html>"
|
||||
|
||||
# Define characters that should be blocked
|
||||
BLOCKED_CHARACTERS = {"•", "™", "∞", "≤", "≥"}
|
||||
|
||||
def contains_blocked_characters(content):
|
||||
"""Check if the content contains explicitly blocked characters."""
|
||||
return any(c in BLOCKED_CHARACTERS for c in content)
|
||||
|
||||
warning = ""
|
||||
try:
|
||||
_is_latin1(template.content)
|
||||
except UnicodeEncodeError:
|
||||
if contains_blocked_characters(template.content): # Block only disallowed characters
|
||||
warning = f"{s1}{s2}"
|
||||
|
||||
# If message is too long, return the length error
|
||||
@@ -705,15 +706,9 @@ def _get_content_count_error_and_message_for_template(template):
|
||||
|
||||
# If there's a warning, return it alone and hide the "Will be charged as..." text
|
||||
if warning:
|
||||
return True, Markup(warning)
|
||||
return False, 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)."
|
||||
)
|
||||
|
||||
return False, Markup(
|
||||
f"Will be charged as {message_count(template.fragment_count, template.template_type)}."
|
||||
)
|
||||
|
||||
191
poetry.lock
generated
191
poetry.lock
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user