django2: Fix 3-tuple ImproperlyConfigured error

https://docs.djangoproject.com/en/2.0/releases/1.9/#passing-a-3-tuple-or-an-app-name-to-include

blueprint django2-support
Change-Id: Ifb9b7501363fe8a3ef417498e0932323240a6dcd
This commit is contained in:
Akihiro Motoki 2017-12-12 15:24:26 +09:00
parent 1a252cb5e8
commit 18684e1ff5
11 changed files with 42 additions and 19 deletions

View File

@ -89,6 +89,24 @@ def access_cached(func):
return inner
def _wrapped_include(arg):
"""Convert the old 3-tuple arg for include() into the new format.
The argument "arg" should be a tuple with 3 elements:
(pattern_list, app_namespace, instance_namespace)
Prior to Django 2.0, django.urls.conf.include() accepts 3-tuple arg
(urlconf, namespace, app_name), but it was droppped in Django 2.0.
This function is used to convert the older 3-tuple used in horizon code
into the new format where namespace needs to be passed as the second arg.
For more details, see
https://docs.djangoproject.com/en/2.0/releases/1.9/#passing-a-3-tuple-or-an-app-name-to-include
"""
pattern_list, app_namespace, instance_namespace = arg
return include((pattern_list, app_namespace), namespace=instance_namespace)
class NotRegistered(Exception):
pass
@ -544,12 +562,13 @@ class Dashboard(Registry, HorizonComponent):
continue
url_slug = panel.slug.replace('.', '/')
urlpatterns.append(url(r'^%s/' % url_slug,
include(panel._decorated_urls)))
_wrapped_include(panel._decorated_urls)))
# Now the default view, which should come last
if not default_panel:
raise NotRegistered('The default panel "%s" is not registered.'
% self.default_panel)
urlpatterns.append(url(r'', include(default_panel._decorated_urls)))
urlpatterns.append(
url(r'', _wrapped_include(default_panel._decorated_urls)))
# Require login if not public.
if not self.public:
@ -867,7 +886,7 @@ class Site(Registry, HorizonComponent):
# Compile the dynamic urlconf.
for dash in self._registry.values():
urlpatterns.append(url(r'^%s/' % dash.slug,
include(dash._decorated_urls)))
_wrapped_include(dash._decorated_urls)))
# add URL for ngdetails
views = import_module('horizon.browsers.views')

View File

@ -32,7 +32,7 @@ urlpatterns = [
# Client-side i18n URLconf.
urlpatterns.extend([
url(r'^i18n/js/(?P<packages>\S+?)/$',
i18n.javascript_catalog,
i18n.JavaScriptCatalog.as_view(),
name='jsi18n'),
url(r'^i18n/setlang/$',
i18n.set_language,

View File

@ -27,11 +27,12 @@ from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.views.generic import TemplateView
import horizon
import horizon.base
from horizon.test.jasmine import jasmine
urlpatterns = [
url(r'', include(horizon.urls)),
url(r'', horizon.base._wrapped_include(horizon.urls)),
url(r"auth/login/", views.login, {'template_name': "auth/login.html"},
name='login'),
url(r'auth/', include('django.contrib.auth.urls')),

View File

@ -25,5 +25,5 @@ urlpatterns = [
views.AdminDetailView.as_view(),
name='detail'),
url(r'^$', views.AdminIndexView.as_view(), name='index'),
url(r'', include(compute_urls, namespace='compute')),
url(r'', include((compute_urls, 'compute'))),
]

View File

@ -53,6 +53,6 @@ urlpatterns = [
url(r'^(?P<network_id>[^/]+)/ports/(?P<port_id>[^/]+)/update$',
port_views.UpdateView.as_view(), name='editport'),
url(r'^subnets/', include(subnet_urls, namespace='subnets')),
url(r'^ports/', include(port_urls, namespace='ports')),
url(r'^subnets/', include((subnet_urls, 'subnets'))),
url(r'^ports/', include((port_urls, 'ports'))),
]

View File

@ -37,7 +37,7 @@ urlpatterns = [
views.EditQosSpecConsumerView.as_view(),
name='edit_qos_spec_consumer'),
url(r'^(?P<type_id>[^/]+)/extras/',
include(extras_urls, namespace='extras')),
include((extras_urls, 'extras'))),
url(r'^(?P<volume_type_id>[^/]+)/create_type_encryption/$',
views.CreateVolumeTypeEncryptionView.as_view(),
name='create_type_encryption'),
@ -48,7 +48,7 @@ urlpatterns = [
views.VolumeTypeEncryptionDetailView.as_view(),
name='type_encryption_detail'),
url(r'^qos_specs/',
include(qos_specs_urls, namespace='qos_specs')),
include((qos_specs_urls, 'qos_specs'))),
url(r'^(?P<volume_type_id>[^/]+)/edit_access/$',
views.EditAccessView.as_view(), name='edit_access'),
]

View File

@ -32,5 +32,5 @@ urlpatterns = [
views.UpdateView.as_view(), name='update'),
url(r'^register/$', views.RegisterView.as_view(), name='register'),
url(r'(?P<identity_provider_id>[^/]+)/protocols/',
include(protocol_urls, namespace='protocols')),
include((protocol_urls, 'protocols'))),
]

View File

@ -34,12 +34,12 @@ if settings.ANGULAR_FEATURES['images_panel']:
# New angular images
urlpatterns = [
url(r'^$', AngularIndexView.as_view(title=title), name='index'),
url(r'', include(image_urls, namespace='images')),
url(r'', include(snapshot_urls, namespace='snapshots')),
url(r'', include((image_urls, 'images'))),
url(r'', include((snapshot_urls, 'snapshots'))),
]
else:
urlpatterns = [
url(r'^$', views.IndexView.as_view(), name='index'),
url(r'', include(image_urls, namespace='images')),
url(r'', include(snapshot_urls, namespace='snapshots')),
url(r'', include((image_urls, 'images'))),
url(r'', include((snapshot_urls, 'snapshots'))),
]

View File

@ -48,6 +48,6 @@ urlpatterns = [
subnet_views.UpdateView.as_view(), name='editsubnet'),
url(r'^(?P<network_id>[^/]+)/ports/(?P<port_id>[^/]+)/update$',
port_views.UpdateView.as_view(), name='editport'),
url(r'^subnets/', include(subnet_urls, namespace='subnets')),
url(r'^ports/', include(port_urls, namespace='ports')),
url(r'^subnets/', include((subnet_urls, 'subnets'))),
url(r'^ports/', include((port_urls, 'ports'))),
]

View File

@ -24,6 +24,8 @@ from django.conf.urls import url
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.views import defaults
import horizon.base
from openstack_dashboard.api import rest
from openstack_dashboard.test.jasmine import jasmine
from openstack_dashboard import views
@ -35,7 +37,7 @@ urlpatterns = [
url(r'^auth/', include('openstack_auth.urls')),
url(r'^api/', include(rest.urls)),
url(r'^jasmine/(.*?)$', jasmine.dispatcher),
url(r'', include(horizon.urls)),
url(r'', horizon.base._wrapped_include(horizon.urls)),
]
# Development static app and project media serving using the staticfiles app.

View File

@ -28,6 +28,7 @@ from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.views import defaults
import horizon
import horizon.base
from openstack_dashboard.api import rest
from openstack_dashboard import views
@ -36,7 +37,7 @@ urlpatterns = [
url(r'^$', views.splash, name='splash'),
url(r'^api/', include(rest.urls)),
url(r'^header/', views.ExtensibleHeaderView.as_view()),
url(r'', include(horizon.urls)),
url(r'', horizon.base._wrapped_include(horizon.urls)),
]
for u in getattr(settings, 'AUTHENTICATION_URLS', ['openstack_auth.urls']):