mirror of
https://github.com/django/django.git
synced 2025-08-03 10:34:04 +00:00
Fixed #27126 -- Made {% regroup %} return a namedtuple to ease unpacking.
This commit is contained in:
parent
7968bb7fad
commit
61b45dff6b
4 changed files with 52 additions and 2 deletions
|
@ -100,3 +100,22 @@ class RegroupTagTests(SimpleTestCase):
|
|||
def test_regroup08(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
self.engine.get_template('regroup08')
|
||||
|
||||
@setup({'regroup_unpack': '{% regroup data by bar as grouped %}'
|
||||
'{% for grouper, group in grouped %}'
|
||||
'{{ grouper }}:'
|
||||
'{% for item in group %}'
|
||||
'{{ item.foo }}'
|
||||
'{% endfor %},'
|
||||
'{% endfor %}'})
|
||||
def test_regroup_unpack(self):
|
||||
output = self.engine.render_to_string('regroup_unpack', {
|
||||
'data': [
|
||||
{'foo': 'c', 'bar': 1},
|
||||
{'foo': 'd', 'bar': 1},
|
||||
{'foo': 'a', 'bar': 2},
|
||||
{'foo': 'b', 'bar': 2},
|
||||
{'foo': 'x', 'bar': 3},
|
||||
],
|
||||
})
|
||||
self.assertEqual(output, '1:cd,2:ab,3:x,')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue