Code

Ticket #11642: 11642-default-namespace-r11413.diff

File 11642-default-namespace-r11413.diff, 1.5 KB (added by mrmachine, 5 years ago)

Get default app_name from urlconf module.

Line 
1Index: django/conf/urls/defaults.py
2===================================================================
3--- django/conf/urls/defaults.py        (revision 11413)
4+++ django/conf/urls/defaults.py        (working copy)
5@@ -1,5 +1,6 @@
6 from django.core.urlresolvers import RegexURLPattern, RegexURLResolver
7 from django.core.exceptions import ImproperlyConfigured
8+from django.utils.importlib import import_module
9 
10 __all__ = ['handler404', 'handler500', 'include', 'patterns', 'url']
11 
12@@ -8,13 +9,18 @@
13 
14 def include(arg, namespace=None, app_name=None):
15     if isinstance(arg, tuple):
16-        # callable returning a namespace hint
17-        if namespace:
18-            raise ImproperlyConfigured('Cannot override the namespace for a dynamic module that provides a namespace')
19-        urlconf_module, app_name, namespace = arg
20+        urlconf_module = arg[0]
21+        app_name = app_name or arg[1]
22+        namespace = namespace or arg[2] or app_name
23     else:
24-        # No namespace hint - use manually provided namespace
25-        urlconf_module = arg
26+        if isinstance(arg, basestring):
27+            urlconf_module = import_module(arg)
28+        else:
29+            urlconf_module = arg
30+        # Get the default application namespace, specified in the app's urlconf.
31+        app_name = app_name or getattr(urlconf_module, 'app_name', None)
32+        # Use the app name as the default instance namespace.
33+        namespace = namespace or app_name
34     return (urlconf_module, app_name, namespace)
35 
36 def patterns(prefix, *args):