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:
parent
c506f4574a
commit
d1b5a0bde5
|
@ -926,20 +926,18 @@ def regroup(parser, token):
|
||||||
{% regroup people|dictsort:"gender" by gender as grouped %}
|
{% regroup people|dictsort:"gender" by gender as grouped %}
|
||||||
|
|
||||||
"""
|
"""
|
||||||
firstbits = token.contents.split(None, 3)
|
bits = token.contents.split()
|
||||||
if len(firstbits) != 4:
|
if len(bits) != 6:
|
||||||
raise TemplateSyntaxError, "'regroup' tag takes five arguments"
|
raise TemplateSyntaxError, "'regroup' tag takes five arguments"
|
||||||
target = parser.compile_filter(firstbits[1])
|
target = parser.compile_filter(bits[1])
|
||||||
if firstbits[2] != 'by':
|
if bits[2] != 'by':
|
||||||
raise TemplateSyntaxError("second argument to 'regroup' tag must be 'by'")
|
raise TemplateSyntaxError("second argument to 'regroup' tag must be 'by'")
|
||||||
lastbits_reversed = firstbits[3][::-1].split(None, 2)
|
if bits[4] != 'as':
|
||||||
if lastbits_reversed[1][::-1] != 'as':
|
|
||||||
raise TemplateSyntaxError("next-to-last argument to 'regroup' tag must"
|
raise TemplateSyntaxError("next-to-last argument to 'regroup' tag must"
|
||||||
" be 'as'")
|
" be 'as'")
|
||||||
|
|
||||||
expression = parser.compile_filter(lastbits_reversed[2][::-1])
|
expression = parser.compile_filter(bits[3])
|
||||||
|
var_name = bits[5]
|
||||||
var_name = lastbits_reversed[0][::-1]
|
|
||||||
return RegroupNode(target, expression, var_name)
|
return RegroupNode(target, expression, var_name)
|
||||||
regroup = register.tag(regroup)
|
regroup = register.tag(regroup)
|
||||||
|
|
||||||
|
|
|
@ -808,6 +808,16 @@ class Templates(unittest.TestCase):
|
||||||
'{% endfor %}',
|
'{% endfor %}',
|
||||||
{}, ''),
|
{}, ''),
|
||||||
|
|
||||||
|
# Test syntax.
|
||||||
|
'regroup03': ('{% regroup data by bar as %}', {},
|
||||||
|
template.TemplateSyntaxError),
|
||||||
|
'regroup04': ('{% regroup data by bar thisaintright grouped %}', {},
|
||||||
|
template.TemplateSyntaxError),
|
||||||
|
'regroup05': ('{% regroup data thisaintright bar as grouped %}', {},
|
||||||
|
template.TemplateSyntaxError),
|
||||||
|
'regroup06': ('{% regroup data by bar as grouped toomanyargs %}', {},
|
||||||
|
template.TemplateSyntaxError),
|
||||||
|
|
||||||
### TEMPLATETAG TAG #######################################################
|
### TEMPLATETAG TAG #######################################################
|
||||||
'templatetag01': ('{% templatetag openblock %}', {}, '{%'),
|
'templatetag01': ('{% templatetag openblock %}', {}, '{%'),
|
||||||
'templatetag02': ('{% templatetag closeblock %}', {}, '%}'),
|
'templatetag02': ('{% templatetag closeblock %}', {}, '%}'),
|
||||||
|
|
Loading…
Reference in New Issue