diff options
| author | Markus Holtermann <info@markusholtermann.eu> | 2015-06-11 18:08:48 +0200 |
|---|---|---|
| committer | Markus Holtermann <info@markusholtermann.eu> | 2015-06-17 23:19:10 +0200 |
| commit | e5cb4e14118f3a508e3bc00ee7cd50bb0f18a61d (patch) | |
| tree | cc079646b4db9f528366c59d67768584387531cd /docs/topics/class-based-views | |
| parent | 2f615b10e6330d27dccbd770a4628200044acf70 (diff) | |
Fixed #24914 -- Added authentication mixins for CBVs
Added the mixins LoginRequiredMixin, PermissionRequiredMixin and
UserPassesTestMixin to contrib.auth as counterparts to the respective
view decorators.
The authentication mixins UserPassesTestMixin, LoginRequiredMixin and
PermissionRequiredMixin have been inspired by django-braces
<https://github.com/brack3t/django-braces/>
Thanks Raphael Michel for the initial patch, tests and docs on the PR
and Ana Balica, Kenneth Love, Marc Tamlyn, and Tim Graham for the
review.
Diffstat (limited to 'docs/topics/class-based-views')
| -rw-r--r-- | docs/topics/class-based-views/intro.txt | 23 |
1 files changed, 0 insertions, 23 deletions
diff --git a/docs/topics/class-based-views/intro.txt b/docs/topics/class-based-views/intro.txt index 6c1ec9233e..6724bec0da 100644 --- a/docs/topics/class-based-views/intro.txt +++ b/docs/topics/class-based-views/intro.txt @@ -173,29 +173,6 @@ that inherits from ``View`` - for example, trying to use a form at the top of a list and combining :class:`~django.views.generic.edit.ProcessFormView` and :class:`~django.views.generic.list.ListView` - won't work as expected. -.. _mixins_that_wrap_as_view: - -Mixins that wrap ``as_view()`` ------------------------------- - -One way to apply common behavior to many classes is to write a mixin that wraps -the :meth:`~django.views.generic.base.View.as_view()` method. - -For example, if you have many generic views that should be decorated with -:func:`~django.contrib.auth.decorators.login_required` you could implement a -mixin like this:: - - from django.contrib.auth.decorators import login_required - - class LoginRequiredMixin(object): - @classmethod - def as_view(cls, **initkwargs): - view = super(LoginRequiredMixin, cls).as_view(**initkwargs) - return login_required(view) - - class MyView(LoginRequiredMixin, ...): - # this is a generic view - ... Handling forms with class-based views ===================================== |
