From 8e262de57abfe52fd4dfeddbc198a9bf41b1e1bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Wed, 6 Mar 2019 20:15:19 +0100 Subject: [PATCH] misc: keep django comments intact in skeleton pages (#25706) --- combo/public/templates/combo/page_template.html | 2 +- combo/public/templatetags/combo.py | 6 +++++- tests/test_public.py | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/combo/public/templates/combo/page_template.html b/combo/public/templates/combo/page_template.html index 7d8d9561..7d22838c 100644 --- a/combo/public/templates/combo/page_template.html +++ b/combo/public/templates/combo/page_template.html @@ -40,7 +40,7 @@ {% trans "Footer" as name %} {% placeholder "footer" name=name acquired=True %} {% skeleton_extra_placeholder footer %} - {% now "Y-m-d H:i:s" %} + {% now "Y-m-d H:i:s" %} {# generation time #} {% end_skeleton_extra_placeholder %} {% endblock %} diff --git a/combo/public/templatetags/combo.py b/combo/public/templatetags/combo.py index 47e498f6..92853d1b 100644 --- a/combo/public/templatetags/combo.py +++ b/combo/public/templatetags/combo.py @@ -25,7 +25,7 @@ from django.conf import settings from django.core import signing from django.core.exceptions import PermissionDenied from django.template import VariableDoesNotExist -from django.template.base import TOKEN_BLOCK, TOKEN_VAR +from django.template.base import TOKEN_BLOCK, TOKEN_VAR, TOKEN_COMMENT from django.template.defaultfilters import stringfilter from django.utils import dateparse @@ -123,11 +123,15 @@ def skeleton_extra_placeholder(parser, token): text.append('{{') elif token.token_type == TOKEN_BLOCK: text.append('{%') + elif token.token_type == TOKEN_COMMENT: + text.append('{# ') text.append(token.contents) if token.token_type == TOKEN_VAR: text.append('}}') elif token.token_type == TOKEN_BLOCK: text.append('%}') + elif token.token_type == TOKEN_COMMENT: + text.append(' #}') nodelist = parser.parse(('end_skeleton_extra_placeholder',)) parser.delete_first_token() diff --git a/tests/test_public.py b/tests/test_public.py index b0983734..561d94d3 100644 --- a/tests/test_public.py +++ b/tests/test_public.py @@ -257,6 +257,7 @@ def test_page_skeleton(app): # check {% now %} inside a skeleton_extra_placeholder is not interpreted assert '{%now' in resp.text + assert '{# generation time #}' in resp.text # check cells in footer are present even if there's no redirection page page.slug = 'index'