From 79ec9214f972099bbf495a8db5c3a61a996831ad Mon Sep 17 00:00:00 2001 From: FreneticScribbler Date: Fri, 21 Feb 2020 01:56:16 +0000 Subject: [PATCH] FIX: Fix broken newlining in PDFs Introduced by a change in Django 2.1 'HTML rendered by form widgets no longer includes a closing slash on void elements, e.g.
. This is incompatible within XHTML, although some widgets already used aspects of HTML5 such as boolean attributes.' --- RIGS/rigboard.py | 1 - RIGS/templates/RIGS/event_print_page.xml | 15 +++++++-------- RIGS/templatetags/filters.py | 14 ++++++++++++++ 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/RIGS/rigboard.py b/RIGS/rigboard.py index abb0ed9e..d91fc222 100644 --- a/RIGS/rigboard.py +++ b/RIGS/rigboard.py @@ -206,7 +206,6 @@ class EventPrint(generic.View): } rml = template.render(context) - buffer = rml2pdf.parseString(rml) merger.append(PdfFileReader(buffer)) buffer.close() diff --git a/RIGS/templates/RIGS/event_print_page.xml b/RIGS/templates/RIGS/event_print_page.xml index 4b1ddfdf..09507167 100644 --- a/RIGS/templates/RIGS/event_print_page.xml +++ b/RIGS/templates/RIGS/event_print_page.xml @@ -1,7 +1,6 @@ +{% load filters %} - - @@ -13,7 +12,7 @@ - {{ object.description|default_if_none:""|linebreaksbr }} + {{ object.description|default_if_none:""|linebreaksxml }} @@ -75,9 +74,9 @@ {% if invoice %} {% if object.organisation.address %} - {{ object.organisation.address|default_if_none:""|linebreaksbr }} + {{ object.organisation.address|default_if_none:""|linebreaksxml }} {% elif object.person.address %} - {{ object.person.address|default_if_none:""|linebreaksbr }} + {{ object.person.address|default_if_none:""|linebreaksxml }} {% endif %} {% endif %} @@ -109,12 +108,12 @@

{{ object.venue.name }}

{% if not invoice %} - {{ object.venue.address|default_if_none:""|linebreaksbr }} + {{ object.venue.address|default_if_none:""|linebreaksxml }} {% endif %} - +

Timings

@@ -185,7 +184,7 @@ {% if item.description %} - {{ item.description|linebreaksbr }} + {{ item.description|linebreaksxml }} {% endif %} diff --git a/RIGS/templatetags/filters.py b/RIGS/templatetags/filters.py index a90ecd64..60b7117d 100644 --- a/RIGS/templatetags/filters.py +++ b/RIGS/templatetags/filters.py @@ -2,10 +2,24 @@ from django import template from django import forms from django.forms.forms import NON_FIELD_ERRORS from django.forms.utils import ErrorDict +from django.utils.text import normalize_newlines +from django.template.defaultfilters import stringfilter +from django.utils.safestring import SafeData, mark_safe +from django.utils.html import escape register = template.Library() +@register.filter(is_safe=True, needs_autoescape=True) +@stringfilter +def linebreaksxml(value, autoescape=True): + autoescape = autoescape and not isinstance(value, SafeData) + value = normalize_newlines(value) + if autoescape: + value = escape(value) + return mark_safe(value.replace('\n', '
')) + + @register.filter def multiply(value, arg): return value * arg