Skip to content

Commit

Permalink
🔥 [#1451] -- delete display_value template tag
Browse files Browse the repository at this point in the history
This has been superceded by the renderer interface
  • Loading branch information
sergei-maertens committed May 9, 2022
1 parent 62121f7 commit 4a45bab
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 99 deletions.
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ omit =
src/openforms/registrations/contrib/email/views.py

[coverage:report]
skip_covered = True
omit =
manage.py
*/tests/test_*
Expand Down
27 changes: 0 additions & 27 deletions src/openforms/emails/templatetags/form_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,3 @@ def summary(context):
@register.simple_tag()
def whitespace(amount: int, base=" ") -> str:
return base * amount


@register.simple_tag(takes_context=True)
def display_value(context, value: Any):
warnings.warn(
"The {% display_value %} template tag is deprecated, please use "
"'openforms.submissions.rendering.renderer.Renderer' instead.",
DeprecationWarning,
)
_is_html = not context.get("rendering_text", False)
if isinstance(value, dict) and value.get("originalName"):
# uploads
return value["originalName"]
if isinstance(value, (list, tuple)):
return "; ".join(display_value(context, v) for v in filter(None, value))

# output - see if we have something that can output as html and as plain text
method = "as_html" if _is_html else "as_plain_text"
formatter = getattr(value, method, None)
if formatter is not None and callable(formatter):
return formatter()

if value is None:
return ""
else:
# fall back to default of string representation
return force_str(value)
50 changes: 0 additions & 50 deletions src/openforms/emails/tests/test_summary_display.py

This file was deleted.

24 changes: 2 additions & 22 deletions src/openforms/formio/formatters/tests/test_kitchensink.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from django.utils.translation import gettext as _

from openforms.emails.templatetags.form_summary import display_value
from openforms.submissions.tests.factories import (
SubmissionFactory,
SubmissionFileAttachmentFactory,
Expand Down Expand Up @@ -99,16 +98,7 @@ def run_kitchensink_test(self, name_data, name_printable):
# check if we have something for all components
self.assertEqual(set(d[0] for d in printable_data), expected_labels)

text_values = dict()
for label, value in printable_data:
text_values[label] = display_value({"rendering_text": True}, value)

html_values = dict()
for label, value in printable_data:
html_values[label] = display_value({"rendering_text": False}, value)

# check if text and html values are same
self.assertEqual(text_values, html_values)
text_values = dict(printable_data)

for label, value in text_printed.items():
with self.subTest(f"{label} -> '{value}'"):
Expand All @@ -129,17 +119,7 @@ def test_appointments_formio(self):
)

printable_data = _get_printable_data(submission)

text_values = dict()
for label, value in printable_data:
text_values[label] = display_value({"rendering_text": True}, value)

html_values = dict()
for label, value in printable_data:
html_values[label] = display_value({"rendering_text": False}, value)

# check if text and html values are same
self.assertEqual(text_values, html_values)
text_values = dict(printable_data)

for label, value in text_printed.items():
with self.subTest(f"{label} -> '{value}'"):
Expand Down

0 comments on commit 4a45bab

Please sign in to comment.