Ticket #11559: 11559.patch
File 11559.patch, 3.4 KB (added by , 14 years ago) |
---|
-
tests/regressiontests/urlpatterns_reverse/namespace_urls.py
44 44 45 45 (r'^included/', include('regressiontests.urlpatterns_reverse.included_namespace_urls')), 46 46 47 (r'^ns-outer/(?P<outer>\d+)/', include('regressiontests.urlpatterns_reverse.included_namespace_urls', namespace='inc-outer')), 48 47 49 ) -
tests/regressiontests/urlpatterns_reverse/tests.py
306 306 self.assertEqual('/ns-included1/normal/', reverse('inc-ns1:inc-normal-view')) 307 307 self.assertEqual('/ns-included1/normal/37/42/', reverse('inc-ns1:inc-normal-view', args=[37,42])) 308 308 self.assertEqual('/ns-included1/normal/42/37/', reverse('inc-ns1:inc-normal-view', kwargs={'arg1':42, 'arg2':37})) 309 self.assertEqual('/ns-outer/42/normal/', reverse('inc-outer:inc-normal-view', kwargs={'outer':42})) 309 310 310 311 def test_multiple_namespace_pattern(self): 311 312 "Namespaces can be embedded" -
django/core/urlresolvers.py
20 20 from django.utils.regex_helper import normalize 21 21 22 22 _resolver_cache = {} # Maps URLconf modules to RegexURLResolver instances. 23 _ns_resolver_cache = {} # Maps namespaces to RegexURLResolver instances. 23 24 _callable_cache = {} # Maps view and url pattern names to their view functions. 24 25 25 26 # SCRIPT_NAME prefixes for each thread are stored here. If there's no entry for … … 106 107 return RegexURLResolver(r'^/', urlconf) 107 108 get_resolver = memoize(get_resolver, _resolver_cache, 1) 108 109 110 def get_ns_resolver(ns_pattern, resolver): 111 # Build a namespaced resolver for the given parent urlconf pattern. 112 # This makes it possible to have captured parameters in the parent 113 # urlconf pattern. 114 ns_resolver = RegexURLResolver(ns_pattern, resolver.url_patterns) 115 return RegexURLResolver(r'^/', [ns_resolver]) 116 get_ns_resolver = memoize(get_ns_resolver, _ns_resolver_cache, 2) 117 109 118 def get_mod_func(callback): 110 119 # Converts 'django.views.news.stories.story_detail' to 111 120 # ['django.views.news.stories', 'story_detail'] … … 360 369 path = parts[1:] 361 370 362 371 resolved_path = [] 372 ns_pattern = '' 363 373 while path: 364 374 ns = path.pop() 365 375 … … 380 390 try: 381 391 extra, resolver = resolver.namespace_dict[ns] 382 392 resolved_path.append(ns) 383 prefix = prefix+ extra393 ns_pattern = ns_pattern + extra 384 394 except KeyError, key: 385 395 if resolved_path: 386 396 raise NoReverseMatch("%s is not a registered namespace inside '%s'" % (key, ':'.join(resolved_path))) 387 397 else: 388 398 raise NoReverseMatch("%s is not a registered namespace" % key) 399 if ns_pattern: 400 resolver = get_ns_resolver(ns_pattern, resolver) 389 401 390 402 return iri_to_uri(u'%s%s' % (prefix, resolver.reverse(view, 391 403 *args, **kwargs)))