Skip to content

Commit

Permalink
conditional placeholders
Browse files Browse the repository at this point in the history
  • Loading branch information
pgaetani committed Nov 18, 2024
1 parent 211fcc2 commit 4036d74
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions notifications_utils/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@ def conditional_text(self):
else:
raise ValueError(f"{self} not conditional")

def get_conditional_body(self, show_conditional):
def get_conditional_body(self, show_conditional, values):
# note: unsanitised/converted
if self.is_conditional():
return self.conditional_text if str2bool(show_conditional) else ""
if str2bool(show_conditional):
conditional_value = values.get(self.conditional_text.strip())
return conditional_value if conditional_value is not None else self.conditional_text
return ""
else:
raise ValueError(f"{self} not conditional")

Expand Down Expand Up @@ -130,7 +133,7 @@ def replace_match(self, match):
return self.format_placeholder(placeholder)

if placeholder.is_conditional():
return placeholder.get_conditional_body(replacement)
return placeholder.get_conditional_body(replacement, self.values)

return replacement

Expand Down

0 comments on commit 4036d74

Please sign in to comment.