Projet

Général

Profil

0001-misc-keep-django-comments-intact-in-skeleton-pages-2.patch

Frédéric Péters, 06 mars 2019 20:17

Télécharger (2,76 ko)

Voir les différences:

Subject: [PATCH 1/2] 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(-)
combo/public/templates/combo/page_template.html
40 40
    {% trans "Footer" as name %}
41 41
    {% placeholder "footer" name=name acquired=True %}
42 42
    {% skeleton_extra_placeholder footer %}
43
    <span style="display: none">{% now "Y-m-d H:i:s" %}</span>
43
    <span style="display: none">{% now "Y-m-d H:i:s" %}</span> {# generation time #}
44 44
    {% end_skeleton_extra_placeholder %}
45 45
  {% endblock %}
46 46
 </div>
combo/public/templatetags/combo.py
25 25
from django.core import signing
26 26
from django.core.exceptions import PermissionDenied
27 27
from django.template import VariableDoesNotExist
28
from django.template.base import TOKEN_BLOCK, TOKEN_VAR
28
from django.template.base import TOKEN_BLOCK, TOKEN_VAR, TOKEN_COMMENT
29 29
from django.template.defaultfilters import stringfilter
30 30
from django.utils import dateparse
31 31

  
......
123 123
            text.append('{{')
124 124
        elif token.token_type == TOKEN_BLOCK:
125 125
            text.append('{%')
126
        elif token.token_type == TOKEN_COMMENT:
127
            text.append('{# ')
126 128
        text.append(token.contents)
127 129
        if token.token_type == TOKEN_VAR:
128 130
            text.append('}}')
129 131
        elif token.token_type == TOKEN_BLOCK:
130 132
            text.append('%}')
133
        elif token.token_type == TOKEN_COMMENT:
134
            text.append(' #}')
131 135

  
132 136
    nodelist = parser.parse(('end_skeleton_extra_placeholder',))
133 137
    parser.delete_first_token()
tests/test_public.py
257 257

  
258 258
    # check {% now %} inside a skeleton_extra_placeholder is not interpreted
259 259
    assert '{%now' in resp.text
260
    assert '{# generation time #}' in resp.text
260 261

  
261 262
    # check cells in footer are present even if there's no redirection page
262 263
    page.slug = 'index'
263
-