On 09/16/2011 11:20 AM, Roald de Vries wrote:
On Sep 16, 2011, at 10:08 AM, Jonathan Slenders wrote:

class ProtectedView(MyView):
    login_required = True

Where 'MyView' checks all the view's options during a dispatch. Never
liked inheritance with multiple base classes...
How would I create my own 'decorators' in this approach?

Cheers, Roald

I think the syntax should be something like:

from django.contrib.auth.decorators import login_required, permission_required

class ProtectedView(MyView):
view_decorators = [login_required, permission_required('foo.can_do_bar')]

The difference to actually decorating the class is small, but I think the above is a bit more explicit about what is happening.

Mixins sound like a good alternative, but does this just move the problem in to mixin class instead of the base view class? That is, how should the mixin class be implemented taking in account that you should be able to decorate the function with multiple decorators? It seems you would need something like ViewDecoratorMixinBase to take care of all the dirty details...

 - Anssi

--
You received this message because you are subscribed to the Google Groups "Django 
developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to