Kaydet (Commit) ad393bee authored tarafından Tim Graham's avatar Tim Graham

Refs #21927 -- Removed include()'s app_name argument per deprecation timeline.

Also removed support for passing a 3-tuple to include() and support for
setting an instance namespace without an application namespace.

Thanks Marten Kenbeek for completing the patch.
üst c6de8cca
import warnings
from importlib import import_module from importlib import import_module
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
...@@ -6,7 +5,6 @@ from django.urls import ( ...@@ -6,7 +5,6 @@ from django.urls import (
LocaleRegexURLResolver, RegexURLPattern, RegexURLResolver, LocaleRegexURLResolver, RegexURLPattern, RegexURLResolver,
) )
from django.utils import six from django.utils import six
from django.utils.deprecation import RemovedInDjango20Warning
__all__ = ['handler400', 'handler403', 'handler404', 'handler500', 'include', 'url'] __all__ = ['handler400', 'handler403', 'handler404', 'handler500', 'include', 'url']
...@@ -16,16 +14,8 @@ handler404 = 'django.views.defaults.page_not_found' ...@@ -16,16 +14,8 @@ handler404 = 'django.views.defaults.page_not_found'
handler500 = 'django.views.defaults.server_error' handler500 = 'django.views.defaults.server_error'
def include(arg, namespace=None, app_name=None): def include(arg, namespace=None):
if app_name and not namespace: app_name = None
raise ValueError('Must specify a namespace if specifying app_name.')
if app_name:
warnings.warn(
'The app_name argument to django.conf.urls.include() is deprecated. '
'Set the app_name in the included URLconf instead.',
RemovedInDjango20Warning, stacklevel=2
)
if isinstance(arg, tuple): if isinstance(arg, tuple):
# callable returning a namespace hint # callable returning a namespace hint
try: try:
...@@ -35,13 +25,11 @@ def include(arg, namespace=None, app_name=None): ...@@ -35,13 +25,11 @@ def include(arg, namespace=None, app_name=None):
raise ImproperlyConfigured( raise ImproperlyConfigured(
'Cannot override the namespace for a dynamic module that provides a namespace' 'Cannot override the namespace for a dynamic module that provides a namespace'
) )
warnings.warn( raise ImproperlyConfigured(
'Passing a 3-tuple to django.conf.urls.include() is deprecated. ' 'Passing a 3-tuple to django.conf.urls.include() is not supported. '
'Pass a 2-tuple containing the list of patterns and app_name, ' 'Pass a 2-tuple containing the list of patterns and app_name, '
'and provide the namespace argument to include() instead.', 'and provide the namespace argument to include() instead.',
RemovedInDjango20Warning, stacklevel=2
) )
urlconf_module, app_name, namespace = arg
else: else:
# No namespace hint - use manually provided namespace # No namespace hint - use manually provided namespace
urlconf_module = arg urlconf_module = arg
...@@ -51,12 +39,11 @@ def include(arg, namespace=None, app_name=None): ...@@ -51,12 +39,11 @@ def include(arg, namespace=None, app_name=None):
patterns = getattr(urlconf_module, 'urlpatterns', urlconf_module) patterns = getattr(urlconf_module, 'urlpatterns', urlconf_module)
app_name = getattr(urlconf_module, 'app_name', app_name) app_name = getattr(urlconf_module, 'app_name', app_name)
if namespace and not app_name: if namespace and not app_name:
warnings.warn( raise ImproperlyConfigured(
'Specifying a namespace in django.conf.urls.include() without ' 'Specifying a namespace in django.conf.urls.include() without '
'providing an app_name is deprecated. Set the app_name attribute ' 'providing an app_name is not supported. Set the app_name attribute '
'in the included module, or pass a 2-tuple containing the list of ' 'in the included module, or pass a 2-tuple containing the list of '
'patterns and app_name instead.', 'patterns and app_name instead.',
RemovedInDjango20Warning, stacklevel=2
) )
namespace = namespace or app_name namespace = namespace or app_name
......
...@@ -53,10 +53,9 @@ parameter is useful. ...@@ -53,10 +53,9 @@ parameter is useful.
``include()`` ``include()``
============= =============
.. function:: include(module, namespace=None, app_name=None) .. function:: include(module, namespace=None)
include(pattern_list) include(pattern_list)
include((pattern_list, app_namespace), namespace=None) include((pattern_list, app_namespace), namespace=None)
include((pattern_list, app_namespace, instance_namespace))
A function that takes a full Python import path to another URLconf module A function that takes a full Python import path to another URLconf module
that should be "included" in this place. Optionally, the :term:`application that should be "included" in this place. Optionally, the :term:`application
...@@ -68,15 +67,12 @@ parameter is useful. ...@@ -68,15 +67,12 @@ parameter is useful.
can be used to set a different instance namespace. can be used to set a different instance namespace.
``include()`` also accepts as an argument either an iterable that returns ``include()`` also accepts as an argument either an iterable that returns
URL patterns, a 2-tuple containing such iterable plus the names of the URL patterns or a 2-tuple containing such iterable plus the names of the
application namespaces, or a 3-tuple containing the iterable and the names application namespaces.
of both the application and instance namespace.
:arg module: URLconf module (or module name) :arg module: URLconf module (or module name)
:arg namespace: Instance namespace for the URL entries being included :arg namespace: Instance namespace for the URL entries being included
:type namespace: string :type namespace: string
:arg app_name: Application namespace for the URL entries being included
:type app_name: string
:arg pattern_list: Iterable of :func:`django.conf.urls.url` instances :arg pattern_list: Iterable of :func:`django.conf.urls.url` instances
:arg app_namespace: Application namespace for the URL entries being included :arg app_namespace: Application namespace for the URL entries being included
:type app_namespace: string :type app_namespace: string
...@@ -85,20 +81,6 @@ parameter is useful. ...@@ -85,20 +81,6 @@ parameter is useful.
See :ref:`including-other-urlconfs` and :ref:`namespaces-and-include`. See :ref:`including-other-urlconfs` and :ref:`namespaces-and-include`.
.. deprecated:: 1.9
Support for the ``app_name`` argument is deprecated and will be removed in
Django 2.0. Specify the ``app_name`` as explained in
:ref:`namespaces-and-include` instead.
Support for passing a 3-tuple is also deprecated and will be removed in
Django 2.0. Pass a 2-tuple containing the pattern list and application
namespace, and use the ``namespace`` argument instead.
Lastly, support for an instance namespace without an application namespace
has been deprecated and will be removed in Django 2.0. Specify the
application namespace or remove the instance namespace.
``handler400`` ``handler400``
============== ==============
......
...@@ -291,3 +291,11 @@ these features. ...@@ -291,3 +291,11 @@ these features.
* The ``mime_type`` attribute of ``django.utils.feedgenerator.Atom1Feed`` and * The ``mime_type`` attribute of ``django.utils.feedgenerator.Atom1Feed`` and
``django.utils.feedgenerator.RssFeed`` is removed. ``django.utils.feedgenerator.RssFeed`` is removed.
* The ``app_name`` argument to ``include()`` is removed.
* Support for passing a 3-tuple as the first argument to ``include()`` is
removed.
* Support for setting a URL instance namespace without an application namespace
is removed.
...@@ -6,6 +6,7 @@ from .views import empty_view, view_class_instance ...@@ -6,6 +6,7 @@ from .views import empty_view, view_class_instance
testobj3 = URLObject('testapp', 'test-ns3') testobj3 = URLObject('testapp', 'test-ns3')
testobj4 = URLObject('testapp', 'test-ns4') testobj4 = URLObject('testapp', 'test-ns4')
app_name = 'included_namespace_urls'
urlpatterns = [ urlpatterns = [
url(r'^normal/$', empty_view, name='inc-normal-view'), url(r'^normal/$', empty_view, name='inc-normal-view'),
url(r'^normal/(?P<arg1>[0-9]+)/(?P<arg2>[0-9]+)/$', empty_view, name='inc-normal-view'), url(r'^normal/(?P<arg1>[0-9]+)/(?P<arg2>[0-9]+)/$', empty_view, name='inc-normal-view'),
...@@ -17,8 +18,8 @@ urlpatterns = [ ...@@ -17,8 +18,8 @@ urlpatterns = [
url(r'^view_class/(?P<arg1>[0-9]+)/(?P<arg2>[0-9]+)/$', view_class_instance, name='inc-view-class'), url(r'^view_class/(?P<arg1>[0-9]+)/(?P<arg2>[0-9]+)/$', view_class_instance, name='inc-view-class'),
url(r'^test3/', include(testobj3.urls)), url(r'^test3/', include(*testobj3.urls)),
url(r'^test4/', include(testobj4.urls)), url(r'^test4/', include(*testobj4.urls)),
url(r'^ns-included3/', include('urlpatterns_reverse.included_urls', namespace='inc-ns3')), url(r'^ns-included3/', include(('urlpatterns_reverse.included_urls', 'included_urls'), namespace='inc-ns3')),
url(r'^ns-included4/', include('urlpatterns_reverse.namespace_urls', namespace='inc-ns4')), url(r'^ns-included4/', include('urlpatterns_reverse.namespace_urls', namespace='inc-ns4')),
] ]
...@@ -12,6 +12,7 @@ otherobj2 = URLObject('nodefault', 'other-ns2') ...@@ -12,6 +12,7 @@ otherobj2 = URLObject('nodefault', 'other-ns2')
newappobj1 = URLObject('newapp') newappobj1 = URLObject('newapp')
app_name = 'namespace_urls'
urlpatterns = [ urlpatterns = [
url(r'^normal/$', views.empty_view, name='normal-view'), url(r'^normal/$', views.empty_view, name='normal-view'),
url(r'^normal/(?P<arg1>[0-9]+)/(?P<arg2>[0-9]+)/$', views.empty_view, name='normal-view'), url(r'^normal/(?P<arg1>[0-9]+)/(?P<arg2>[0-9]+)/$', views.empty_view, name='normal-view'),
...@@ -27,12 +28,12 @@ urlpatterns = [ ...@@ -27,12 +28,12 @@ urlpatterns = [
url(r'^unnamed/normal/(?P<arg1>[0-9]+)/(?P<arg2>[0-9]+)/$', views.empty_view), url(r'^unnamed/normal/(?P<arg1>[0-9]+)/(?P<arg2>[0-9]+)/$', views.empty_view),
url(r'^unnamed/view_class/(?P<arg1>[0-9]+)/(?P<arg2>[0-9]+)/$', views.view_class_instance), url(r'^unnamed/view_class/(?P<arg1>[0-9]+)/(?P<arg2>[0-9]+)/$', views.view_class_instance),
url(r'^test1/', include(testobj1.urls)), url(r'^test1/', include(*testobj1.urls)),
url(r'^test2/', include(testobj2.urls)), url(r'^test2/', include(*testobj2.urls)),
url(r'^default/', include(default_testobj.urls)), url(r'^default/', include(*default_testobj.urls)),
url(r'^other1/', include(otherobj1.urls)), url(r'^other1/', include(*otherobj1.urls)),
url(r'^other[246]/', include(otherobj2.urls)), url(r'^other[246]/', include(*otherobj2.urls)),
url(r'^newapp1/', include(newappobj1.app_urls, 'new-ns1')), url(r'^newapp1/', include(newappobj1.app_urls, 'new-ns1')),
url(r'^new-default/', include(newappobj1.app_urls)), url(r'^new-default/', include(newappobj1.app_urls)),
...@@ -43,10 +44,12 @@ urlpatterns = [ ...@@ -43,10 +44,12 @@ urlpatterns = [
url(r'^ns-included[135]/', include('urlpatterns_reverse.included_namespace_urls', namespace='inc-ns1')), url(r'^ns-included[135]/', include('urlpatterns_reverse.included_namespace_urls', namespace='inc-ns1')),
url(r'^ns-included2/', include('urlpatterns_reverse.included_namespace_urls', namespace='inc-ns2')), url(r'^ns-included2/', include('urlpatterns_reverse.included_namespace_urls', namespace='inc-ns2')),
url(r'^app-included/', include('urlpatterns_reverse.included_namespace_urls', 'inc-app', 'inc-app')), url(r'^app-included/', include('urlpatterns_reverse.included_namespace_urls', 'inc-app')),
url(r'^included/', include('urlpatterns_reverse.included_namespace_urls')), url(r'^included/', include('urlpatterns_reverse.included_namespace_urls')),
url(r'^inc(?P<outer>[0-9]+)/', include('urlpatterns_reverse.included_urls', namespace='inc-ns5')), url(
r'^inc(?P<outer>[0-9]+)/', include(('urlpatterns_reverse.included_urls', 'included_urls'), namespace='inc-ns5')
),
url(r'^included/([0-9]+)/', include('urlpatterns_reverse.included_namespace_urls')), url(r'^included/([0-9]+)/', include('urlpatterns_reverse.included_namespace_urls')),
url( url(
......
...@@ -18,7 +18,7 @@ class URLObject(object): ...@@ -18,7 +18,7 @@ class URLObject(object):
@property @property
def urls(self): def urls(self):
return self.urlpatterns, self.app_name, self.namespace return (self.urlpatterns, self.app_name), self.namespace
@property @property
def app_urls(self): def app_urls(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment