use the new names of URL related class (#49283)
This commit is contained in:
parent
6539d8ddbf
commit
7eedc0bbcc
|
@ -1,15 +1,20 @@
|
|||
# Decorating URL includes, <https://djangosnippets.org/snippets/2532/>
|
||||
|
||||
from django.urls import RegexURLPattern, RegexURLResolver
|
||||
try:
|
||||
from django.urls import URLPattern, URLResolver
|
||||
except ImportError:
|
||||
# django < 2.0 compatibility
|
||||
from django.urls import RegexURLPattern as URLPattern, RegexURLResolver as URLResolver
|
||||
|
||||
class DecoratedURLPattern(RegexURLPattern):
|
||||
|
||||
class DecoratedURLPattern(URLPattern):
|
||||
def resolve(self, *args, **kwargs):
|
||||
result = super(DecoratedURLPattern, self).resolve(*args, **kwargs)
|
||||
if result:
|
||||
result.func = self._decorate_with(result.func)
|
||||
return result
|
||||
|
||||
class DecoratedRegexURLResolver(RegexURLResolver):
|
||||
class DecoratedRegexURLResolver(URLResolver):
|
||||
def resolve(self, *args, **kwargs):
|
||||
result = super(DecoratedRegexURLResolver, self).resolve(*args, **kwargs)
|
||||
if result:
|
||||
|
@ -20,11 +25,11 @@ def decorated_includes(func, includes, *args, **kwargs):
|
|||
urlconf_module, app_name, namespace = includes
|
||||
|
||||
for item in urlconf_module:
|
||||
if isinstance(item, RegexURLPattern):
|
||||
if isinstance(item, URLPattern):
|
||||
item.__class__ = DecoratedURLPattern
|
||||
item._decorate_with = func
|
||||
|
||||
elif isinstance(item, RegexURLResolver):
|
||||
elif isinstance(item, URLResolver):
|
||||
item.__class__ = DecoratedRegexURLResolver
|
||||
item._decorate_with = func
|
||||
|
||||
|
|
Loading…
Reference in New Issue