On 20 October 2010 19:42, Luke Plant <l.plant...@cantab.net> wrote:
> On Wed, 2010-10-20 at 16:05 +0200, Łukasz Rekucki wrote:
>
>> OTOH, it's annoying to have to write an dispatch() method with a super
>> inside (which effectively does nothing), just to apply a decorator.
>
> That's a good point I hadn't thought of, as are Russell's other points.
>
> Just to put it on the table, another option we thought of at one point
> was to have a 'decorators' attribute on the class, which is a list of
> decorators that is applied by the as_view() method.  It would in theory
> allow you to add decorators to either end of the set of decorators that
> are applied, something like this:
>
> class MyView(SomeOtherView):
>
>    decorators = SomeOtherView.decorators + [my_dec_1, my_dec_2]

I'm addicted to decorators so I would probably end up with a decorator
that adds items
to that list :)

>
> It gets a bit trickier with multiple inheritance.  I don't know if that
> would be too much of a big deal - I would imagine that most of the mixin
> classes would not be providing decorators.  But then my imagination is
> probably limited.

I didn't find a use case for decorating a mixin yet, but i'm only
starting to explore (I didn't have this problem in any of my own
applications that use CBV). There is a simple pattern to change a
decorator into a mixin that should play well with multiple
inheritance.

On a related note, while writing a class_decorator() I noticed that
method_decorator() doesn't work with decorators that set attributes on
the view (like csrf_exempt). This is because the decorator is invoked
on a closure inside _wrapper() during method call (i.e. during method
call, not class creation), while as_view() only sees _wrapper - which
has no attributes.

-- 
Łukasz Rekucki

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

Reply via email to