summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorPaul Donohue <git@PaulSD.com>2018-04-08 13:35:24 -0400
committerTim Graham <timograham@gmail.com>2018-04-12 13:11:08 -0400
commit33a0b7ac815588ed92dca215e153390af8bdbdda (patch)
tree151047d74bb30076489c6b1b846ede5826c161a2 /django
parentee17bb8a67a9e7e688da6e6f4b3be1b3a69c09b0 (diff)
Fixed #29296 -- Fixed crashes in admindocs when a view is a callable object.
Diffstat (limited to 'django')
-rw-r--r--django/contrib/admindocs/middleware.py4
-rw-r--r--django/contrib/admindocs/utils.py6
-rw-r--r--django/contrib/admindocs/views.py9
3 files changed, 12 insertions, 7 deletions
diff --git a/django/contrib/admindocs/middleware.py b/django/contrib/admindocs/middleware.py
index b5024de72c..4da5604106 100644
--- a/django/contrib/admindocs/middleware.py
+++ b/django/contrib/admindocs/middleware.py
@@ -2,6 +2,8 @@ from django.conf import settings
from django.http import HttpResponse
from django.utils.deprecation import MiddlewareMixin
+from .utils import get_view_name
+
class XViewMiddleware(MiddlewareMixin):
"""
@@ -24,5 +26,5 @@ class XViewMiddleware(MiddlewareMixin):
if request.method == 'HEAD' and (request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS or
(request.user.is_active and request.user.is_staff)):
response = HttpResponse()
- response['X-View'] = "%s.%s" % (view_func.__module__, view_func.__name__)
+ response['X-View'] = get_view_name(view_func)
return response
diff --git a/django/contrib/admindocs/utils.py b/django/contrib/admindocs/utils.py
index 3b5b5bb1fc..fa72d60d57 100644
--- a/django/contrib/admindocs/utils.py
+++ b/django/contrib/admindocs/utils.py
@@ -18,6 +18,12 @@ else:
docutils_is_available = True
+def get_view_name(view_func):
+ mod_name = view_func.__module__
+ view_name = getattr(view_func, '__qualname__', view_func.__class__.__name__)
+ return mod_name + '.' + view_name
+
+
def trim_docstring(docstring):
"""
Uniformly trim leading/trailing whitespace from docstrings.
diff --git a/django/contrib/admindocs/views.py b/django/contrib/admindocs/views.py
index e332607ce8..2da015b73f 100644
--- a/django/contrib/admindocs/views.py
+++ b/django/contrib/admindocs/views.py
@@ -23,6 +23,8 @@ from django.utils.inspect import (
from django.utils.translation import gettext as _
from django.views.generic import TemplateView
+from .utils import get_view_name
+
# Exclude methods starting with these strings from documentation
MODEL_METHODS_EXCLUDE = ('_', 'add_', 'delete', 'save', 'set_')
@@ -124,18 +126,13 @@ class TemplateFilterIndexView(BaseAdminDocsView):
class ViewIndexView(BaseAdminDocsView):
template_name = 'admin_doc/view_index.html'
- @staticmethod
- def _get_full_name(func):
- mod_name = func.__module__
- return '%s.%s' % (mod_name, func.__qualname__)
-
def get_context_data(self, **kwargs):
views = []
urlconf = import_module(settings.ROOT_URLCONF)
view_functions = extract_views_from_urlpatterns(urlconf.urlpatterns)
for (func, regex, namespace, name) in view_functions:
views.append({
- 'full_name': self._get_full_name(func),
+ 'full_name': get_view_name(func),
'url': simplify_regex(regex),
'url_name': ':'.join((namespace or []) + (name and [name] or [])),
'namespace': ':'.join((namespace or [])),