Le 28 mai 2010 à 00:01, Luke Plant a écrit : > 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). We discussed that point with Jacob and it looks like it's easier to modify urlresolvers to create a new instance of the class when we detect it's a class, this should solve the thread safety issue. Do you see any drawback to this approach? That way we can declare decorators via a decorators' list [1] or directly in the class [2]. I'm not fond of the second way, decorating a decorator, but we can create decorators dedicated to class based views easily that way. > > 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. Agreed, I'll make that change.
Thanks, David [1] http://github.com/bfirsh/django-class-based-views/blob/master/class_based_views/tests/views.py#L24 [2] http://github.com/bfirsh/django-class-based-views/blob/master/class_based_views/tests/views.py#L43 -- 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.