Commit 66076268 authored by Łukasz Langa's avatar Łukasz Langa
Browse files

Fixed #20126 -- XViewMiddleware moved to django.contrib.admindocs.middleware

parent a7e28352
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
from django.conf import settings
from django import http

class XViewMiddleware(object):
    """
    Adds an X-View header to internal HEAD requests -- used by the documentation system.
    """
    def process_view(self, request, view_func, view_args, view_kwargs):
        """
        If the request method is HEAD and either the IP is internal or the
        user is a logged-in staff member, quickly return with an x-header
        indicating the view function.  This is used by the documentation module
        to lookup the view function for an arbitrary page.
        """
        assert hasattr(request, 'user'), (
            "The XView middleware requires authentication middleware to be "
            "installed. Edit your MIDDLEWARE_CLASSES setting to insert "
            "'django.contrib.auth.middleware.AuthenticationMiddleware'.")
        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 = http.HttpResponse()
            response['X-View'] = "%s.%s" % (view_func.__module__, view_func.__name__)
            return response
+5 −22
Original line number Diff line number Diff line
from django.conf import settings
from django import http
"""XViewMiddleware has been moved to django.contrib.admindocs.middleware."""

class XViewMiddleware(object):
    """
    Adds an X-View header to internal HEAD requests -- used by the documentation system.
    """
    def process_view(self, request, view_func, view_args, view_kwargs):
        """
        If the request method is HEAD and either the IP is internal or the
        user is a logged-in staff member, quickly return with an x-header
        indicating the view function.  This is used by the documentation module
        to lookup the view function for an arbitrary page.
        """
        assert hasattr(request, 'user'), (
            "The XView middleware requires authentication middleware to be "
            "installed. Edit your MIDDLEWARE_CLASSES setting to insert "
            "'django.contrib.auth.middleware.AuthenticationMiddleware'.")
        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 = http.HttpResponse()
            response['X-View'] = "%s.%s" % (view_func.__module__, view_func.__name__)
            return response
import warnings
warnings.warn(__doc__, PendingDeprecationWarning, stacklevel=2)

from django.contrib.admindocs.middleware import XViewMiddleware
+5 −5
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ the following:
* **Optional:** Linking to templates requires the :setting:`ADMIN_FOR`
  setting to be configured.
* **Optional:** Using the admindocs bookmarklets requires the
  :mod:`XViewMiddleware<django.middleware.doc>` to be installed.
  :mod:`XViewMiddleware<django.contrib.admindocs.middleware>` to be installed.

Once those steps are complete, you can start browsing the documentation by
going to your admin interface and clicking the "Documentation" link in the
@@ -156,7 +156,7 @@ Edit this object
Using these bookmarklets requires that you are either logged into the
:mod:`Django admin <django.contrib.admin>` as a
:class:`~django.contrib.auth.models.User` with
:attr:`~django.contrib.auth.models.User.is_staff` set to `True`, or
that the :mod:`django.middleware.doc` middleware and
:mod:`XViewMiddleware <django.middleware.doc>` are installed and you
are accessing the site from an IP address listed in :setting:`INTERNAL_IPS`.
:attr:`~django.contrib.auth.models.User.is_staff` set to `True`, or that the
:mod:`XViewMiddleware <django.contrib.admindocs.middleware>` is installed and
you are accessing the site from an IP address listed in
:setting:`INTERNAL_IPS`.
+0 −13
Original line number Diff line number Diff line
@@ -71,19 +71,6 @@ Adds a few conveniences for perfectionists:
* Sends broken link notification emails to :setting:`MANAGERS` (see
  :doc:`/howto/error-reporting`).

View metadata middleware
------------------------

.. module:: django.middleware.doc
   :synopsis: Middleware to help your app self-document.

.. class:: XViewMiddleware

Sends custom ``X-View`` HTTP headers to HEAD requests that come from IP
addresses defined in the :setting:`INTERNAL_IPS` setting. This is used by
Django's :doc:`automatic documentation system </ref/contrib/admin/admindocs>`.
Depends on :class:`~django.contrib.auth.middleware.AuthenticationMiddleware`.

GZip middleware
---------------

+1 −1
Original line number Diff line number Diff line
@@ -1243,7 +1243,7 @@ Default: ``()`` (Empty tuple)
A tuple of IP addresses, as strings, that:

* See debug comments, when :setting:`DEBUG` is ``True``
* Receive X headers if the ``XViewMiddleware`` is installed (see
* Receive X headers in admindocs if the ``XViewMiddleware`` is installed (see
  :doc:`/topics/http/middleware`)

.. setting:: LANGUAGE_CODE
Loading