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
This commit is contained in:
		 Daniel Hahler
					Daniel Hahler
				
			
				
					committed by
					
						 Johannes Linke
						Johannes Linke
					
				
			
			
				
	
			
			
			 Johannes Linke
						Johannes Linke
					
				
			
						parent
						
							9d9b20a14a
						
					
				
				
					commit
					a13c143e26
				
			| @@ -13,14 +13,18 @@ from compressor.conf import settings | |||||||
| from compressor.signals import post_compress | from compressor.signals import post_compress | ||||||
| from compressor.tests.test_base import css_tag, test_dir | 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. |     A shortcut for testing template output. | ||||||
|     """ |     """ | ||||||
|     if context_dict is None: |     if context_dict is None: | ||||||
|         context_dict = {} |         context_dict = {} | ||||||
|     c = Context(context_dict) |     if context is None: | ||||||
|  |         context = Context | ||||||
|  |     c = context(context_dict) | ||||||
|     t = Template(template_string) |     t = Template(template_string) | ||||||
|     return t.render(c).strip() |     return t.render(c).strip() | ||||||
|  |  | ||||||
| @@ -126,6 +130,14 @@ class TemplatetagTestCase(TestCase): | |||||||
|         context = kwargs['context'] |         context = kwargs['context'] | ||||||
|         self.assertEqual('foo', context['compressed']['name']) |         self.assertEqual('foo', context['compressed']['name']) | ||||||
|  |  | ||||||
|  |     def test_sekizai_only_once(self): | ||||||
|  |         template = """{% load sekizai_tags %}{% addtoblock "js" %} | ||||||
|  |         <script type="text/javascript">var tmpl="{% templatetag openblock %} if x == 3 %}x IS 3{% templatetag openblock %} endif %}"</script> | ||||||
|  |         {% endaddtoblock %}{% render_block "js" postprocessor "compressor.contrib.sekizai.compress" %} | ||||||
|  |         """ | ||||||
|  |         out = '<script type="text/javascript" src="/static/CACHE/js/e9fce10d884d.js"></script>' | ||||||
|  |         self.assertEqual(out, render(template, self.context, SekizaiContext)) | ||||||
|  |  | ||||||
|  |  | ||||||
| class PrecompilerTemplatetagTestCase(TestCase): | class PrecompilerTemplatetagTestCase(TestCase): | ||||||
|     def setUp(self): |     def setUp(self): | ||||||
|   | |||||||
| @@ -8,3 +8,4 @@ BeautifulSoup==3.2.1 | |||||||
| unittest2==1.0.0 | unittest2==1.0.0 | ||||||
| coffin==0.4.0 | coffin==0.4.0 | ||||||
| jingo==0.7 | jingo==0.7 | ||||||
|  | django-sekizai==0.8.2 | ||||||
|   | |||||||
							
								
								
									
										4
									
								
								tox.ini
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								tox.ini
									
									
									
									
									
								
							| @@ -10,6 +10,7 @@ two = | |||||||
|     unittest2==1.0.0 |     unittest2==1.0.0 | ||||||
|     jingo==0.7 |     jingo==0.7 | ||||||
|     coffin==0.4.0 |     coffin==0.4.0 | ||||||
|  |     django-sekizai==0.8.2 | ||||||
| two_six = | two_six = | ||||||
|     flake8==2.4.0 |     flake8==2.4.0 | ||||||
|     coverage==3.7.1 |     coverage==3.7.1 | ||||||
| @@ -21,6 +22,7 @@ two_six = | |||||||
|     unittest2==1.0.0 |     unittest2==1.0.0 | ||||||
|     jingo==0.7 |     jingo==0.7 | ||||||
|     coffin==0.4.0 |     coffin==0.4.0 | ||||||
|  |     django-sekizai==0.8.2 | ||||||
| three = | three = | ||||||
|     flake8==2.4.0 |     flake8==2.4.0 | ||||||
|     coverage==3.7.1 |     coverage==3.7.1 | ||||||
| @@ -31,6 +33,7 @@ three = | |||||||
|     beautifulsoup4==4.4.0 |     beautifulsoup4==4.4.0 | ||||||
|     jingo==0.7 |     jingo==0.7 | ||||||
|     coffin==0.4.0 |     coffin==0.4.0 | ||||||
|  |     django-sekizai==0.8.2 | ||||||
| three_two = | three_two = | ||||||
|     flake8==2.4.0 |     flake8==2.4.0 | ||||||
|     coverage==3.7.1 |     coverage==3.7.1 | ||||||
| @@ -41,6 +44,7 @@ three_two = | |||||||
|     beautifulsoup4==4.4.0 |     beautifulsoup4==4.4.0 | ||||||
|     jingo==0.7 |     jingo==0.7 | ||||||
|     coffin==0.4.0 |     coffin==0.4.0 | ||||||
|  |     django-sekizai==0.8.2 | ||||||
| [tox] | [tox] | ||||||
| envlist = | envlist = | ||||||
|     {py26,py27}-1.4.X, |     {py26,py27}-1.4.X, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user