On Thu, Jun 17, 2010 at 12:26 PM, Patryk Zawadzki <pat...@pld-linux.org> wrote:
> On Thu, Jun 17, 2010 at 1:44 AM, Nick Fitzgerald <fitz...@gmail.com> wrote:
>> I have forked bfirsh's code as well on
>> github: http://github.com/fitzgen/django-class-based-views
>> I have changed the code to use __new__ rather than copying self. I have also
>> merged in daonb's commit to make request implicit to all methods via
>> self.request.
>> All feedback is very welcome! :)
>
> Is there any reason why all of you think not passing request around is a gain?
>
> Would you recommend anyone to do:
>
> ---- 8< ----
>
> request = None
>
> def my_view():
>    global request
>    return HttpResponse('Hi, %s' % (request.user.get_full_name(), ))
>
> def my_other_view():
>    globl request
>    return HttpResponse('Hello again, %s' % (request.user.get_full_name(), ))
>
> # ...
>
> ---- 8< ----
>
> As I seriously see no difference between this and pushing stuff to 
> self.request.

Please take a deeper look at his code. He doesn't use __init__. He
uses __new__, so each request gets his own View instance.

Instead of

aa = AwesomeAdd()
foo = aa(3, 5)

the __new__-based approach allows to do this:

foo = AwesomeAdd(3, 5)

IOW, the "constructor" directly returns an HttpResponse (foo) instead
of an AwesomeAdd instance.

Bye,
Waldemar Kornewald

-- 
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