From a13c143e261cb436768d99926f45e932b8fbb0aa Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sat, 20 Jun 2015 16:35:15 +0200 Subject: [PATCH] contrib.sekizai: fix double-rendering: use TextNode, not Template Use `TextNode(data)` instead of `Template(data).nodelist` to parse the template only once. The report and fix was initially provided by Aaron McMillin. Fixes #361 Closes #362 --- compressor/tests/test_templatetags.py | 16 ++++++++++++++-- requirements/tests.txt | 1 + tox.ini | 4 ++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/compressor/tests/test_templatetags.py b/compressor/tests/test_templatetags.py index 321c239..6b935a4 100644 --- a/compressor/tests/test_templatetags.py +++ b/compressor/tests/test_templatetags.py @@ -13,14 +13,18 @@ from compressor.conf import settings from compressor.signals import post_compress from compressor.tests.test_base import css_tag, test_dir +from sekizai.context import SekizaiContext -def render(template_string, context_dict=None): + +def render(template_string, context_dict=None, context=None): """ A shortcut for testing template output. """ if context_dict is None: context_dict = {} - c = Context(context_dict) + if context is None: + context = Context + c = context(context_dict) t = Template(template_string) return t.render(c).strip() @@ -126,6 +130,14 @@ class TemplatetagTestCase(TestCase): context = kwargs['context'] self.assertEqual('foo', context['compressed']['name']) + def test_sekizai_only_once(self): + template = """{% load sekizai_tags %}{% addtoblock "js" %} + + {% endaddtoblock %}{% render_block "js" postprocessor "compressor.contrib.sekizai.compress" %} + """ + out = '' + self.assertEqual(out, render(template, self.context, SekizaiContext)) + class PrecompilerTemplatetagTestCase(TestCase): def setUp(self): diff --git a/requirements/tests.txt b/requirements/tests.txt index c75d484..3985c54 100644 --- a/requirements/tests.txt +++ b/requirements/tests.txt @@ -8,3 +8,4 @@ BeautifulSoup==3.2.1 unittest2==1.0.0 coffin==0.4.0 jingo==0.7 +django-sekizai==0.8.2 diff --git a/tox.ini b/tox.ini index 3e165a3..50fc0fd 100644 --- a/tox.ini +++ b/tox.ini @@ -10,6 +10,7 @@ two = unittest2==1.0.0 jingo==0.7 coffin==0.4.0 + django-sekizai==0.8.2 two_six = flake8==2.4.0 coverage==3.7.1 @@ -21,6 +22,7 @@ two_six = unittest2==1.0.0 jingo==0.7 coffin==0.4.0 + django-sekizai==0.8.2 three = flake8==2.4.0 coverage==3.7.1 @@ -31,6 +33,7 @@ three = beautifulsoup4==4.4.0 jingo==0.7 coffin==0.4.0 + django-sekizai==0.8.2 three_two = flake8==2.4.0 coverage==3.7.1 @@ -41,6 +44,7 @@ three_two = beautifulsoup4==4.4.0 jingo==0.7 coffin==0.4.0 + django-sekizai==0.8.2 [tox] envlist = {py26,py27}-1.4.X,