On Thursday 27 May 2010 17:29:28 David Larlet wrote: > Hello, > > We're working on this with Ben during djangocon.eu sprint [1]. Any > comment appreciated, still a work in progress though.
Looks cool. I think Jari's idea of a class method to instantiate the classes would be a great pattern to establish - something like an 'as_view' classmethod on the base class which returns a view function that uses the class: @classmethod def as_view(cls, *initargs, **initkwargs): def view(*args, **kwargs): obj = cls(*initargs, **initkwargs) return obj(*args, **kwargs) return view The developer can choose whether to write 'MyClassView.as_view()' directly into the URLconf, or put a line into views.py like 'my_view = MyClassView.as_view()' This will solve the thread safety issue, and doesn't require another import for a decorator, as Jari pointed out. We could decide whether to apply decorators inside as_view() or __call__(). The argument for putting it in 'as_view' is that __call__ does some processing that you might want to skip entirely (e.g. the get_object() call - if we applied a 'cache_page' decorator, we wouldn't want the get_object() call to be made at all if there was a cache hit). On that point, I think 'GenericView' should be split into 'ClassView' and 'GenericView'. The get_object() call is probably not a good thing to have on a base class. Regards, 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.