Ticket #13154: django-smarter-reverse.patch
File django-smarter-reverse.patch, 3.1 KB (added by , 15 years ago) |
---|
-
django/core/urlresolvers.py
177 177 else: 178 178 parent = normalize(pattern.regex.pattern) 179 179 for name in pattern.reverse_dict: 180 for matches, pat in pattern.reverse_dict.getlist(name):180 for matches, pat, defaults in pattern.reverse_dict.getlist(name): 181 181 new_matches = [] 182 182 for piece, p_args in parent: 183 183 new_matches.extend([(piece + suffix, p_args + args) for (suffix, args) in matches]) 184 lookups.appendlist(name, (new_matches, p_pattern + pat ))184 lookups.appendlist(name, (new_matches, p_pattern + pat, dict(defaults, **pattern.default_kwargs))) 185 185 for namespace, (prefix, sub_pattern) in pattern.namespace_dict.items(): 186 186 namespaces[namespace] = (p_pattern + prefix, sub_pattern) 187 187 for app_name, namespace_list in pattern.app_dict.items(): 188 188 apps.setdefault(app_name, []).extend(namespace_list) 189 189 else: 190 190 bits = normalize(p_pattern) 191 lookups.appendlist(pattern.callback, (bits, p_pattern ))192 lookups.appendlist(pattern.name, (bits, p_pattern ))191 lookups.appendlist(pattern.callback, (bits, p_pattern, pattern.default_args)) 192 lookups.appendlist(pattern.name, (bits, p_pattern, pattern.default_args)) 193 193 self._reverse_dict = lookups 194 194 self._namespace_dict = namespaces 195 195 self._app_dict = apps … … 275 275 except (ImportError, AttributeError), e: 276 276 raise NoReverseMatch("Error importing '%s': %s." % (lookup_view, e)) 277 277 possibilities = self.reverse_dict.getlist(lookup_view) 278 for possibility, pattern in possibilities:278 for possibility, pattern, defaults in possibilities: 279 279 for result, params in possibility: 280 280 if args: 281 281 if len(args) != len(params): … … 283 283 unicode_args = [force_unicode(val) for val in args] 284 284 candidate = result % dict(zip(params, unicode_args)) 285 285 else: 286 if set(kwargs.keys() ) != set(params):286 if set(kwargs.keys() + defaults.keys()) != set(params + defaults.keys()): 287 287 continue 288 matches = True 289 for k, v in defaults.items(): 290 if kwargs.get(k, v) != v: 291 matches = False 292 break 293 if not matches: 294 continue 288 295 unicode_kwargs = dict([(k, force_unicode(v)) for (k, v) in kwargs.items()]) 289 296 candidate = result % unicode_kwargs 290 297 if re.search(u'^%s' % pattern, candidate, re.UNICODE):