#26626: Update decorator_from_middleware to work with new-style middleware
-------------------------------+--------------------------------------
     Reporter:  Tim Graham     |                    Owner:  Carl Meyer
         Type:  New feature    |                   Status:  assigned
    Component:  HTTP handling  |                  Version:  master
     Severity:  Normal         |               Resolution:
     Keywords:                 |             Triage Stage:  Accepted
    Has patch:  0              |      Needs documentation:  0
  Needs tests:  0              |  Patch needs improvement:  0
Easy pickings:  0              |                    UI/UX:  0
-------------------------------+--------------------------------------

Comment (by Andreas Pelme):

 Another use case:

 We have a custom authentication mechanism that is not tied to
 contrib.admin for our main site.

 However, we use contrib.auth for administrative accounts. To make it very
 clear which views needs a real user, we have disabled the auth middleware
 globally and use a custom admin site that selectively enables auth:

 {{{
 from django.contrib import admin
 from django.contrib.auth.middleware import AuthenticationMiddleware

 from django.utils.decorators import decorator_from_middleware


 auth_decorator = decorator_from_middleware(AuthenticationMiddleware)


 class AdminSite(admin.AdminSite):
     def admin_view(self, view, cacheable=False):
         super_wrapper = super().admin_view(view, cacheable=cacheable)
         return auth_decorator(super_wrapper)
 }}}


 (This use case is fine and works fine in Django 1.10 since Django's built
 in `AuthenticationMiddleware` is both old and new-style, but I just wanted
 to highlight that `decorator_from_middleware` is useful in different
 contexts)

--
Ticket URL: <https://code.djangoproject.com/ticket/26626#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.4dd04184d271c178856fe3f27bfcffb7%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to