Ticket #17675: 17675.patch
File 17675.patch, 3.6 KB (added by , 13 years ago) |
---|
-
tests/regressiontests/templates/tests.py
8 8 # before importing 'template'. 9 9 settings.configure() 10 10 11 from datetime import date time, timedelta11 from datetime import date, datetime, timedelta 12 12 import time 13 13 import os 14 14 import sys … … 1376 1376 '{% endfor %},' 1377 1377 '{% endfor %}', 1378 1378 {}, ''), 1379 1380 # Regression test for #17675 1381 'regroup03': ('{% regroup data by at|date:"m" as grouped %}' 1382 '{% for group in grouped %}' 1383 '{{ group.grouper }}:' 1384 '{% for item in group.list %}' 1385 '{{ item.at|date:"d" }}' 1386 '{% endfor %},' 1387 '{% endfor %}', 1388 {'data': [{'at': date(2012, 2, 14)}, 1389 {'at': date(2012, 2, 28)}, 1390 {'at': date(2012, 7, 4)}]}, 1391 '02:1428,07:04,'), 1392 1379 1393 ### SSI TAG ######################################################## 1380 1394 1381 1395 # Test normal behavior -
django/template/defaulttags.py
10 10 TemplateSyntaxError, VariableDoesNotExist, InvalidTemplateLibrary, 11 11 BLOCK_TAG_START, BLOCK_TAG_END, VARIABLE_TAG_START, VARIABLE_TAG_END, 12 12 SINGLE_BRACE_START, SINGLE_BRACE_END, COMMENT_TAG_START, COMMENT_TAG_END, 13 get_library, token_kwargs, kwarg_re)13 VARIABLE_ATTRIBUTE_SEPARATOR, get_library, token_kwargs, kwarg_re) 14 14 from django.template.smartif import IfParser, Literal 15 15 from django.template.defaultfilters import date 16 16 from django.utils.encoding import smart_str, smart_unicode … … 287 287 self.target, self.expression = target, expression 288 288 self.var_name = var_name 289 289 290 def resolve_expression(self, obj, context): 291 # Put obj in context under self.var_name, because it's guaranteed 292 # not to be used (yet) when this function is called. 293 context[self.var_name] = obj 294 return self.expression.resolve(context, True) 295 290 296 def render(self, context): 291 297 obj_list = self.target.resolve(context, True) 292 298 if obj_list == None: … … 298 304 context[self.var_name] = [ 299 305 {'grouper': key, 'list': list(val)} 300 306 for key, val in 301 groupby(obj_list, lambda v, f=self.expression.resolve: f(v, True))307 groupby(obj_list, lambda obj: self.resolve_expression(obj, context)) 302 308 ] 303 309 return '' 304 310 … … 1112 1118 if lastbits_reversed[1][::-1] != 'as': 1113 1119 raise TemplateSyntaxError("next-to-last argument to 'regroup' tag must" 1114 1120 " be 'as'") 1115 1116 expression = parser.compile_filter(lastbits_reversed[2][::-1])1117 1118 1121 var_name = lastbits_reversed[0][::-1] 1122 # Hack -- RegroupNode will put each item in 'target' in the context 1123 # under the key 'var_name' and evaluate this expression, 1124 # before finally saving the final groups under the same key. 1125 expression = parser.compile_filter(var_name + 1126 VARIABLE_ATTRIBUTE_SEPARATOR + 1127 lastbits_reversed[2][::-1]) 1119 1128 return RegroupNode(target, expression, var_name) 1120 1129 1121 1130 @register.tag