Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Removed some reverse string craziness from the regroup template tag a…

…rgument checking and added a few syntax tests.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@6956 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit d1b5a0bde593f80968079cd9d1c971d92a53353e 1 parent c506f45
Gary Wilson Jr. authored December 19, 2007
16  django/template/defaulttags.py
@@ -926,20 +926,18 @@ def regroup(parser, token):
926 926
         {% regroup people|dictsort:"gender" by gender as grouped %}
927 927
 
928 928
     """
929  
-    firstbits = token.contents.split(None, 3)
930  
-    if len(firstbits) != 4:
  929
+    bits = token.contents.split()
  930
+    if len(bits) != 6:
931 931
         raise TemplateSyntaxError, "'regroup' tag takes five arguments"
932  
-    target = parser.compile_filter(firstbits[1])
933  
-    if firstbits[2] != 'by':
  932
+    target = parser.compile_filter(bits[1])
  933
+    if bits[2] != 'by':
934 934
         raise TemplateSyntaxError("second argument to 'regroup' tag must be 'by'")
935  
-    lastbits_reversed = firstbits[3][::-1].split(None, 2)
936  
-    if lastbits_reversed[1][::-1] != 'as':
  935
+    if bits[4] != 'as':
937 936
         raise TemplateSyntaxError("next-to-last argument to 'regroup' tag must"
938 937
                                   " be 'as'")
939 938
 
940  
-    expression = parser.compile_filter(lastbits_reversed[2][::-1])
941  
-
942  
-    var_name = lastbits_reversed[0][::-1]
  939
+    expression = parser.compile_filter(bits[3])
  940
+    var_name = bits[5]
943 941
     return RegroupNode(target, expression, var_name)
944 942
 regroup = register.tag(regroup)
945 943
 
10  tests/regressiontests/templates/tests.py
@@ -807,6 +807,16 @@ def get_template_tests(self):
807 807
                           '{% endfor %},' + \
808 808
                           '{% endfor %}',
809 809
                           {}, ''),
  810
+            
  811
+            # Test syntax.
  812
+            'regroup03': ('{% regroup data by bar as %}', {},
  813
+                          template.TemplateSyntaxError),
  814
+            'regroup04': ('{% regroup data by bar thisaintright grouped %}', {},
  815
+                          template.TemplateSyntaxError),
  816
+            'regroup05': ('{% regroup data thisaintright bar as grouped %}', {},
  817
+                          template.TemplateSyntaxError),
  818
+            'regroup06': ('{% regroup data by bar as grouped toomanyargs %}', {},
  819
+                          template.TemplateSyntaxError),
810 820
 
811 821
             ### TEMPLATETAG TAG #######################################################
812 822
             'templatetag01': ('{% templatetag openblock %}', {}, '{%'),

0 notes on commit d1b5a0b

Please sign in to comment.
Something went wrong with that request. Please try again.