Skip to content

Commit

Permalink
Refs #21927 -- Removed include()'s app_name argument per deprecation …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
timgraham committed Jan 18, 2017
1 parent c6de8cc commit ad393be
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 125 deletions.
25 changes: 6 additions & 19 deletions django/conf/urls/__init__.py
@@ -1,12 +1,10 @@
import warnings
from importlib import import_module

from django.core.exceptions import ImproperlyConfigured
from django.urls import (
LocaleRegexURLResolver, RegexURLPattern, RegexURLResolver,
)
from django.utils import six
from django.utils.deprecation import RemovedInDjango20Warning

__all__ = ['handler400', 'handler403', 'handler404', 'handler500', 'include', 'url']

Expand All @@ -16,16 +14,8 @@
handler500 = 'django.views.defaults.server_error'


def include(arg, namespace=None, app_name=None):
if app_name and not namespace:
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
)

def include(arg, namespace=None):
app_name = None
if isinstance(arg, tuple):
# callable returning a namespace hint
try:
Expand All @@ -35,13 +25,11 @@ def include(arg, namespace=None, app_name=None):
raise ImproperlyConfigured(
'Cannot override the namespace for a dynamic module that provides a namespace'
)
warnings.warn(
'Passing a 3-tuple to django.conf.urls.include() is deprecated. '
raise ImproperlyConfigured(
'Passing a 3-tuple to django.conf.urls.include() is not supported. '
'Pass a 2-tuple containing the list of patterns and app_name, '
'and provide the namespace argument to include() instead.',
RemovedInDjango20Warning, stacklevel=2
)
urlconf_module, app_name, namespace = arg
else:
# No namespace hint - use manually provided namespace
urlconf_module = arg
Expand All @@ -51,12 +39,11 @@ def include(arg, namespace=None, app_name=None):
patterns = getattr(urlconf_module, 'urlpatterns', urlconf_module)
app_name = getattr(urlconf_module, 'app_name', app_name)
if namespace and not app_name:
warnings.warn(
raise ImproperlyConfigured(
'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 '
'patterns and app_name instead.',
RemovedInDjango20Warning, stacklevel=2
)

namespace = namespace or app_name
Expand Down
24 changes: 3 additions & 21 deletions docs/ref/urls.txt
Expand Up @@ -53,10 +53,9 @@ parameter is useful.
``include()``
=============

.. function:: include(module, namespace=None, app_name=None)
.. function:: include(module, namespace=None)
include(pattern_list)
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
that should be "included" in this place. Optionally, the :term:`application
Expand All @@ -68,15 +67,12 @@ parameter is useful.
can be used to set a different instance namespace.

``include()`` also accepts as an argument either an iterable that returns
URL patterns, a 2-tuple containing such iterable plus the names of the
application namespaces, or a 3-tuple containing the iterable and the names
of both the application and instance namespace.
URL patterns or a 2-tuple containing such iterable plus the names of the
application namespaces.

:arg module: URLconf module (or module name)
:arg namespace: Instance namespace for the URL entries being included
: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 app_namespace: Application namespace for the URL entries being included
:type app_namespace: string
Expand All @@ -85,20 +81,6 @@ parameter is useful.

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``
==============

Expand Down
8 changes: 8 additions & 0 deletions docs/releases/2.0.txt
Expand Up @@ -291,3 +291,11 @@ these features.

* The ``mime_type`` attribute of ``django.utils.feedgenerator.Atom1Feed`` and
``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.
7 changes: 4 additions & 3 deletions tests/urlpatterns_reverse/included_namespace_urls.py
Expand Up @@ -6,6 +6,7 @@
testobj3 = URLObject('testapp', 'test-ns3')
testobj4 = URLObject('testapp', 'test-ns4')

app_name = 'included_namespace_urls'
urlpatterns = [
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'),
Expand All @@ -17,8 +18,8 @@

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'^test4/', include(testobj4.urls)),
url(r'^ns-included3/', include('urlpatterns_reverse.included_urls', namespace='inc-ns3')),
url(r'^test3/', include(*testobj3.urls)),
url(r'^test4/', include(*testobj4.urls)),
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')),
]
17 changes: 10 additions & 7 deletions tests/urlpatterns_reverse/namespace_urls.py
Expand Up @@ -12,6 +12,7 @@

newappobj1 = URLObject('newapp')

app_name = 'namespace_urls'
urlpatterns = [
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'),
Expand All @@ -27,12 +28,12 @@
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'^test1/', include(testobj1.urls)),
url(r'^test2/', include(testobj2.urls)),
url(r'^default/', include(default_testobj.urls)),
url(r'^test1/', include(*testobj1.urls)),
url(r'^test2/', include(*testobj2.urls)),
url(r'^default/', include(*default_testobj.urls)),

url(r'^other1/', include(otherobj1.urls)),
url(r'^other[246]/', include(otherobj2.urls)),
url(r'^other1/', include(*otherobj1.urls)),
url(r'^other[246]/', include(*otherobj2.urls)),

url(r'^newapp1/', include(newappobj1.app_urls, 'new-ns1')),
url(r'^new-default/', include(newappobj1.app_urls)),
Expand All @@ -43,10 +44,12 @@
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'^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'^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(
Expand Down

0 comments on commit ad393be

Please sign in to comment.