Skip to content

Commit

Permalink
#169 Upgrade Mistune to v3 (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
kalbfled authored Dec 18, 2024
1 parent ab7d6c4 commit 14881f7
Show file tree
Hide file tree
Showing 12 changed files with 1,251 additions and 2,520 deletions.
11 changes: 5 additions & 6 deletions notifications_utils/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,11 @@ def __init__(
markdown_lists=False,
redact_missing_personalisation=False,
preview_mode=False,
is_letter_template=False
):
self.content = content
self.values = values
self.markdown_lists = markdown_lists
self.preview_mode = preview_mode
self.is_letter_template = is_letter_template
if not with_brackets:
self.placeholder_tag = self.placeholder_tag_no_brackets
if preview_mode:
Expand All @@ -105,10 +103,10 @@ def __init__(
}[html]
self.redact_missing_personalisation = redact_missing_personalisation

def __str__(self):
def __str__(self) -> str:
if self.values:
return self.replaced
return self.formatted
return str(self.formatted)

def __repr__(self):
return "{}(\"{}\", {})".format(self.__class__.__name__, self.content, self.values) # TODO: more real
Expand Down Expand Up @@ -155,11 +153,12 @@ def replace_match(self, match):
elif replaced_value is not None:
return self.get_replacement(placeholder)

# TODO: investigate why this fallback is necessary and potentially remove to enable truly conditional placeholders
# TODO - Investigate why this fallback is necessary, and potentially remove
# it to enable truly conditional placeholders.
return self.format_match(match)

def is_okay_to_have_null_values(self, placeholder) -> bool:
return self.redact_missing_personalisation or placeholder.is_conditional() or self.is_letter_template
return self.redact_missing_personalisation or placeholder.is_conditional()

def get_replacement(self, placeholder):
replacement = self.values.get(placeholder.name)
Expand Down
Loading

0 comments on commit 14881f7

Please sign in to comment.