Added some code to utils.urls.url() to output remaining explicit url names together with the matching dotted-path to the view function.

- Legacy-Id: 12921
This commit is contained in:
Henrik Levkowetz 2017-02-25 20:32:20 +00:00
parent 7e6bed667a
commit 84527c9df6

View file

@ -5,8 +5,16 @@ import debug # pyflakes:ignore
from inspect import isclass
from django.conf.urls import url as django_url
from django.views.generic import View
def url(regex, view, kwargs=None, name=None):
if callable(view) and hasattr(view, '__name__'):
view_name = "%s.%s" % (view.__module__, view.__name__)
elif callable(view) and hasattr(view, '__class__'):
view_name = "%s.%s" % (view.__module__, view.__class__.__name__)
else:
view_name = regex
if name:
branch = 'name'
elif isinstance(view, (list, tuple)):
@ -16,16 +24,22 @@ def url(regex, view, kwargs=None, name=None):
name = view
elif callable(view) and hasattr(view, '__name__'):
branch = 'callable'
name = "%s.%s" % (view.__module__, view.__name__)
name = view_name
elif isinstance(view, View):
branch = 'view'
elif isclass(view) or hasattr(view, '__class__'):
branch = 'class'
else:
branch = 'notimpl'
raise NotImplementedError("Auto-named url from view of type %s: %s" % (type(view), view))
if branch == 'name':
# List explicit url names with accompanying view dotted-path:
#debug.say("%s %s" % (view_name, name))
pass
if name:
branch = branch # silent pyflakes
#debug.show('branch')
#debug.show('name')
pass
return django_url(regex, view, kwargs=kwargs, name=name)