Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Reverted 'regroup' template tag changes from [6956], as they caused b…

…ug #6271, which affects one of my sites. I don't have time to inspect the #6271 patch, so I'm reverting this change in the interim, to fix the bug immediately.

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

0 notes on commit 3d52ce7

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