Skip to content

Commit

Permalink
Merge branch 'fix/816-ae-reports-server-error-if-braces' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanWillitts committed Aug 12, 2024
2 parents 9a30638 + 49362c5 commit 46ec338
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions edc_adverse_event/templatetags/edc_adverse_event_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,16 @@ class DeathReportModel(DeathReportModelMixin, BaseUuidModel): ...
register = template.Library()


def wrapx(text, length):
def wrapx(text: str, length: int) -> str:
if length:
return "<BR>".join(wrap(text, length))
return text


def escape_braces(text: str) -> str:
return text.replace("{", "{{").replace("}", "}}")


def select_ae_template(relative_path):
"""Returns a template object."""
local_path = f"{get_adverse_event_app_label()}/bootstrap{get_bootstrap_version()}/"
Expand All @@ -78,10 +82,14 @@ def format_ae_description(context, ae_initial, wrap_length):
context["YES"] = YES
context["ae_initial"] = ae_initial
try:
context["sae_reason"] = format_html(wrapx(ae_initial.sae_reason.name, wrap_length))
context["sae_reason"] = format_html(
wrapx(escape_braces(ae_initial.sae_reason.name), wrap_length)
)
except AttributeError:
context["sae_reason"] = ""
context["ae_description"] = format_html(wrapx(ae_initial.ae_description, wrap_length))
context["ae_description"] = format_html(
wrapx(escape_braces(ae_initial.ae_description), wrap_length)
)
return context


Expand All @@ -96,13 +104,15 @@ def format_ae_followup_description(context, ae_followup, wrap_length):
context["ae_initial"] = ae_followup.ae_initial
try:
context["sae_reason"] = format_html(
wrapx(ae_followup.ae_initial.sae_reason.name, wrap_length)
wrapx(escape_braces(ae_followup.ae_initial.sae_reason.name), wrap_length)
)
except AttributeError:
context["sae_reason"] = ""
context["relevant_history"] = format_html(wrapx(ae_followup.relevant_history, wrap_length))
context["relevant_history"] = format_html(
wrapx(escape_braces(ae_followup.relevant_history), wrap_length)
)
context["ae_description"] = format_html(
wrapx(ae_followup.ae_initial.ae_description, wrap_length)
wrapx(escape_braces(ae_followup.ae_initial.ae_description), wrap_length)
)
return context

Expand All @@ -116,10 +126,12 @@ def format_ae_susar_description(context, ae_susar, wrap_length):
context["ae_susar"] = ae_susar
context["ae_initial"] = ae_susar.ae_initial
context["sae_reason"] = format_html(
"<BR>".join(wrap(ae_susar.ae_initial.sae_reason.name, wrap_length or 35))
"<BR>".join(
wrap(escape_braces(ae_susar.ae_initial.sae_reason.name), wrap_length or 35)
)
)
context["ae_description"] = format_html(
wrapx(ae_susar.ae_initial.ae_description, wrap_length)
wrapx(escape_braces(ae_susar.ae_initial.ae_description), wrap_length)
)
return context

Expand Down

0 comments on commit 46ec338

Please sign in to comment.