Ticket #4915: django-smarter-resolver.patch
File django-smarter-resolver.patch, 2.1 KB (added by , 17 years ago) |
---|
-
django/core/urlresolvers.py
212 212 return '<%s %s %s>' % (self.__class__.__name__, self.urlconf_name, self.regex.pattern) 213 213 214 214 def _get_reverse_dict(self): 215 def _add(key, val): 216 self._reverse_dict.setdefault(key, []).append(val) 215 217 if not self._reverse_dict and hasattr(self.urlconf_module, 'urlpatterns'): 216 218 for pattern in reversed(self.urlconf_module.urlpatterns): 217 219 if isinstance(pattern, RegexURLResolver): 218 for key, value in pattern.reverse_dict.iteritems(): 219 self._reverse_dict[key] = (pattern,) + value 220 for key, values in pattern.reverse_dict.iteritems(): 221 for value in values: 222 _add(key, (pattern,) + value) 220 223 else: 221 self._reverse_dict[pattern.callback] = (pattern,) 222 self._reverse_dict[pattern.name] = (pattern,) 224 _add(pattern.callback, (pattern,)) 225 if pattern.name: 226 _add(pattern.name, (pattern,)) 223 227 return self._reverse_dict 224 228 reverse_dict = property(_get_reverse_dict) 225 229 … … 278 282 lookup_view = get_callable(lookup_view, True) 279 283 except (ImportError, AttributeError): 280 284 raise NoReverseMatch 281 if lookup_view in self.reverse_dict: 282 return u''.join([reverse_helper(part.regex, *args, **kwargs) for part in self.reverse_dict[lookup_view]]) 285 for k, v in self.reverse_dict.iteritems(): 286 print "%s -> %s" % (repr(k), repr(v)) 287 for candidate in self.reverse_dict.get(lookup_view, []): 288 result = u''.join([reverse_helper(part.regex, *args, **kwargs) for part in candidate]) 289 if self.resolve(u'/' + result) == (lookup_view, args, kwargs): 290 return result 283 291 raise NoReverseMatch 284 292 285 293 def reverse_helper(self, lookup_view, *args, **kwargs):