diff --git a/django/middleware/doc.py b/django/middleware/doc.py index 4f91503c433..ee3fe2cb2f7 100644 --- a/django/middleware/doc.py +++ b/django/middleware/doc.py @@ -12,6 +12,10 @@ class XViewMiddleware(object): 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() diff --git a/docs/ref/middleware.txt b/docs/ref/middleware.txt index 15642171460..07873219ff2 100644 --- a/docs/ref/middleware.txt +++ b/docs/ref/middleware.txt @@ -80,6 +80,7 @@ View metadata middleware 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 `. +Depends on :class:`~django.contrib.auth.middleware.AuthenticationMiddleware`. GZIP middleware --------------- diff --git a/tests/regressiontests/utils/decorators.py b/tests/regressiontests/utils/decorators.py index 837cc7d39e0..96f4dd4e7a3 100644 --- a/tests/regressiontests/utils/decorators.py +++ b/tests/regressiontests/utils/decorators.py @@ -1,24 +1,26 @@ from django.http import HttpResponse -from django.middleware.doc import XViewMiddleware from django.template import Template, Context from django.template.response import TemplateResponse from django.test import TestCase, RequestFactory from django.utils.decorators import decorator_from_middleware -xview_dec = decorator_from_middleware(XViewMiddleware) +class ProcessViewMiddleware(object): + def process_view(self, request, view_func, view_args, view_kwargs): + pass +process_view_dec = decorator_from_middleware(ProcessViewMiddleware) -@xview_dec -def xview(request): +@process_view_dec +def process_view(request): return HttpResponse() -class ClassXView(object): +class ClassProcessView(object): def __call__(self, request): return HttpResponse() -class_xview = xview_dec(ClassXView()) +class_process_view = process_view_dec(ClassProcessView()) class FullMiddleware(object): @@ -52,13 +54,13 @@ class DecoratorFromMiddlewareTests(TestCase): """ Test a middleware that implements process_view. """ - xview(self.rf.get('/')) + process_view(self.rf.get('/')) def test_callable_process_view_middleware(self): """ Test a middleware that implements process_view, operating on a callable class. """ - class_xview(self.rf.get('/')) + class_process_view(self.rf.get('/')) def test_full_dec_normal(self): """