Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #14506 -- Added an assertion to XViewMiddleware about the depen…

…dency on the authentication middleware. Thanks, vanschelven.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16496 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 43cb78fafde45fae9e057d29878c2ebf40aef873 1 parent c29e454
@jezdez jezdez authored
View
4 django/middleware/doc.py
@@ -12,6 +12,10 @@ def process_view(self, request, view_func, view_args, view_kwargs):
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()
View
1  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 </ref/contrib/admin/admindocs>`.
+Depends on :class:`~django.contrib.auth.middleware.AuthenticationMiddleware`.
GZIP middleware
---------------
View
18 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 @@ def test_process_view_middleware(self):
"""
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):
"""
Please sign in to comment.
Something went wrong with that request. Please try again.