1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Removed some reverse string craziness from the regroup template tag argument checking and added a few syntax tests.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@6956 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Gary Wilson Jr
2007-12-19 06:11:55 +00:00
parent c506f4574a
commit d1b5a0bde5
2 changed files with 17 additions and 9 deletions

View File

@@ -926,20 +926,18 @@ def regroup(parser, token):
{% regroup people|dictsort:"gender" by gender as grouped %}
"""
firstbits = token.contents.split(None, 3)
if len(firstbits) != 4:
bits = token.contents.split()
if len(bits) != 6:
raise TemplateSyntaxError, "'regroup' tag takes five arguments"
target = parser.compile_filter(firstbits[1])
if firstbits[2] != 'by':
target = parser.compile_filter(bits[1])
if bits[2] != 'by':
raise TemplateSyntaxError("second argument to 'regroup' tag must be 'by'")
lastbits_reversed = firstbits[3][::-1].split(None, 2)
if lastbits_reversed[1][::-1] != 'as':
if bits[4] != 'as':
raise TemplateSyntaxError("next-to-last argument to 'regroup' tag must"
" be 'as'")
expression = parser.compile_filter(lastbits_reversed[2][::-1])
var_name = lastbits_reversed[0][::-1]
expression = parser.compile_filter(bits[3])
var_name = bits[5]
return RegroupNode(target, expression, var_name)
regroup = register.tag(regroup)