diff options
| author | Paul Donohue <git@PaulSD.com> | 2018-04-08 13:35:24 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2018-04-12 13:11:53 -0400 |
| commit | 1ed31efb8753f6c4fd263033ddebc2f008e43a68 (patch) | |
| tree | 085ef498db188ea54a98a4a0ccfe3d8a8ad4976a /django | |
| parent | d5018abf1c4e3c68f1a825d05eb9035325707e16 (diff) | |
[2.0.x] Fixed #29296 -- Fixed crashes in admindocs when a view is a callable object.
Backport of 33a0b7ac815588ed92dca215e153390af8bdbdda from master
Diffstat (limited to 'django')
| -rw-r--r-- | django/contrib/admindocs/middleware.py | 4 | ||||
| -rw-r--r-- | django/contrib/admindocs/utils.py | 6 | ||||
| -rw-r--r-- | django/contrib/admindocs/views.py | 9 |
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 b6a23c8849..992c62d2bd 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 e45898c025..c4b9ec6917 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_') @@ -128,18 +130,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 [])), |
