datatracker/ietf/utils/urls.py
Henrik Levkowetz aa5e61d958 Updated all urlpatterns to use ietf.utils.urls.url() instead of django's,
in order to autogenerate dotted path url pattern names.  Updated a number
of url reverses to use dotted path, and removed explicit url pattern names
as needed.

Changed some imports to prevent import of ietf.urls before django
initialization was complete.


Changed 3 cases of form classes being curried to functions; django 1.10
didn't accept that.

Started converting old-style middleware classes to new-style middleware
functions (incomplete).

Tweaked a nomcom decorator to preserve function names and attributes, like
a good decorator should.

Replaced the removed django templatetag 'removetags' with our own version
which uses bleach, and does sanitizing in addition to removing explicitly
mentionied html tags.

Rewrote the filename argument handling in a management command which had
broken with the upgrade.
 - Legacy-Id: 12818
2017-02-11 14:43:01 +00:00

31 lines
1,002 B
Python

# Copyright The IETF Trust 2016, All Rights Reserved
import six
import debug # pyflakes:ignore
from inspect import isclass
from django.conf.urls import url as django_url
def url(regex, view, kwargs=None, name=None):
if name:
branch = 'name'
elif isinstance(view, (list, tuple)):
branch = 'list'
elif isinstance(view, six.string_types):
branch = 'string'
name = view
elif callable(view) and hasattr(view, '__name__'):
branch = 'callable'
name = "%s.%s" % (view.__module__, view.__name__)
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 name:
branch = branch # silent pyflakes
#debug.show('branch')
#debug.show('name')
pass
return django_url(regex, view, kwargs=kwargs, name=name)