mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Fixed #4506 -- Changed "regroup" template tag to use __eq__ instead of repr()
for grouping equality checking. Thanks, Brian Harring. git-svn-id: http://code.djangoproject.com/svn/django/trunk@5484 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
		| @@ -4,6 +4,7 @@ from django.template import Node, NodeList, Template, Context, resolve_variable | ||||
| from django.template import TemplateSyntaxError, VariableDoesNotExist, BLOCK_TAG_START, BLOCK_TAG_END, VARIABLE_TAG_START, VARIABLE_TAG_END, SINGLE_BRACE_START, SINGLE_BRACE_END, COMMENT_TAG_START, COMMENT_TAG_END | ||||
| from django.template import get_library, Library, InvalidTemplateLibrary | ||||
| from django.conf import settings | ||||
| from django.utils.itercompat import groupby | ||||
| import sys | ||||
| import re | ||||
|  | ||||
| @@ -258,15 +259,10 @@ class RegroupNode(Node): | ||||
|         if obj_list == None: # target_var wasn't found in context; fail silently | ||||
|             context[self.var_name] = [] | ||||
|             return () | ||||
|         output = [] # list of dictionaries in the format {'grouper': 'key', 'list': [list of contents]} | ||||
|         for obj in obj_list: | ||||
|             grouper = self.expression.resolve(obj, True) | ||||
|             # TODO: Is this a sensible way to determine equality? | ||||
|             if output and repr(output[-1]['grouper']) == repr(grouper): | ||||
|                 output[-1]['list'].append(obj) | ||||
|             else: | ||||
|                 output.append({'grouper': grouper, 'list': [obj]}) | ||||
|         context[self.var_name] = output | ||||
|         # List of dictionaries in the format | ||||
|         # {'grouper': 'key', 'list': [list of contents]}. | ||||
|         context[self.var_name] = [{'grouper':key, 'list':list(val)} for key, val in | ||||
|             groupby(obj_list, lambda v, f=self.expression.resolve: f(v, True))] | ||||
|         return () | ||||
|  | ||||
| def include_is_allowed(filepath): | ||||
|   | ||||
		Reference in New Issue
	
	Block a user