On Thursday 13 May 2010 12:08:26 Luke Plant wrote: > 3) Add the decorators when you call 'instantiator' (which, by the > way, I would rather call 'make_view' or something more specific). > You would then have, *in views.py*: > > 3a) my_view = some_decorator(make_view(MyViewClass)) > > or possibly (though I don't think this adds much): > > 3b) my_view = make_view(MyViewClass, > decorators=[some_decorator]) >
I had some more thoughts about this. One problem with applying the decorators after is if someone is re-using the class (e.g. subclassing), but forgets to apply some *necessary* decorators when creating the view from it. One work-around is that 'make_view' checks the class itself for a 'decorators' attribute, and applies them: def make_view(viewclass): def view(request, *args, **kwargs): obj = viewclass() return obj(request, *args, **kwargs) for f in getattr(viewclass, 'decorators', []): view = f(view) return view This would make it harder to forget, but would still allow subclasses to adjust the decorators that are used by default. It won't help in the case where people use the class directly in the URLconf, but I don't think that should be encouraged anyway. Luke -- "Oh, look. I appear to be lying at the bottom of a very deep, dark hole. That seems a familiar concept. What does it remind me of? Ah, I remember. Life." (Marvin the paranoid android) Luke Plant || http://lukeplant.me.uk/ -- 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.