mirror of
https://github.com/django/django.git
synced 2025-08-04 19:08:28 +00:00
Fixed #26830 -- Prevented the 'with' templatetag from resetting the cycle variable to its initial state.
This commit is contained in:
parent
31e053edfa
commit
3ae3a1f9fa
4 changed files with 66 additions and 1 deletions
|
@ -145,3 +145,25 @@ class CycleTagTests(SimpleTestCase):
|
|||
"""
|
||||
output = self.engine.render_to_string('cycle29', {'values': [1, 2, 3, 4, 5, 6, 7, 8, 8, 8, 9, 9]})
|
||||
self.assertEqual(output, 'bcabcabcccaa')
|
||||
|
||||
@setup({
|
||||
'cycle30': "{% cycle 'a' 'b' 'c' as cycler silent %}"
|
||||
"{% for x in values %}"
|
||||
"{% with doesnothing=irrelevant %}"
|
||||
"{% ifchanged x %}"
|
||||
"{% cycle cycler %}{{ cycler }}"
|
||||
"{% else %}"
|
||||
"{{ cycler }}"
|
||||
"{% endifchanged %}"
|
||||
"{% endwith %}"
|
||||
"{% endfor %}"})
|
||||
def test_cycle30(self):
|
||||
"""
|
||||
A {% with %} tag shouldn't reset the {% cycle %} variable.
|
||||
"""
|
||||
output = self.engine.render_to_string(
|
||||
'cycle30', {
|
||||
'irrelevant': 1,
|
||||
'values': [1, 2, 3, 4, 5, 6, 7, 8, 8, 8, 9, 9]
|
||||
})
|
||||
self.assertEqual(output, 'bcabcabcccaa')
|
||||
|
|
|
@ -204,6 +204,37 @@ class ContextTests(SimpleTestCase):
|
|||
self.assertEqual(str(warns[2].message), msg2)
|
||||
self.assertEqual(str(warns[3].message), msg2)
|
||||
|
||||
def test_set_upward(self):
|
||||
c = Context({'a': 1})
|
||||
c.set_upward('a', 2)
|
||||
self.assertEqual(c.get('a'), 2)
|
||||
|
||||
def test_set_upward_empty_context(self):
|
||||
empty_context = Context()
|
||||
empty_context.set_upward('a', 1)
|
||||
self.assertEqual(empty_context.get('a'), 1)
|
||||
|
||||
def test_set_upward_with_push(self):
|
||||
"""
|
||||
The highest context which has the given key is used.
|
||||
"""
|
||||
c = Context({'a': 1})
|
||||
c.push({'a': 2})
|
||||
c.set_upward('a', 3)
|
||||
self.assertEqual(c.get('a'), 3)
|
||||
c.pop()
|
||||
self.assertEqual(c.get('a'), 1)
|
||||
|
||||
def test_set_upward_with_push_no_match(self):
|
||||
"""
|
||||
The highest context is used if the given key isn't found.
|
||||
"""
|
||||
c = Context({'b': 1})
|
||||
c.push({'b': 2})
|
||||
c.set_upward('a', 2)
|
||||
self.assertEqual(len(c.dicts), 3)
|
||||
self.assertEqual(c.dicts[-1]['a'], 2)
|
||||
|
||||
|
||||
class RequestContextTests(SimpleTestCase):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue