On Mon, 2010-10-04 at 13:08 -0400, Alex Gaynor wrote:

> Given that the primary complain against the __new__ solution is that
> it's unintuitive to Python programmers that instantiating their class
> results in some other class, why not simply go with a more explicit
> classmethod.  Simply used as:
> 
> url("^articles/$", ArticlesView.dispatch).
> 
> It seems to address all concerns: it's explicit, safe to assign
> attributes, Pythonic, and fails loudly if used improperly (using
> AritlcesView would result in an Exception being throw since it doesn't
> return an HttpResponse, and using, and ArticlesView() an error about
> not being callable).
> 
> Last idea, I swear,
> Alex
> 

I've put together a repos with a bunch of scripts that demonstrate in
about a page of code the essence of what we are trying to achieve
(without all the detail about the actual dispatch to HTTP verbs etc).
Start with naive.py:

http://bitbucket.org/spookylukey/django-class-views-experiments/src/tip/naive.py

(Just run as 'python naive.py' to see the output). Browse up a level to
see the other variants.

I implemented Alex's latest idea in classmethod.py (with 'as_view'
instead of 'dispatch', to avoid name clashes).  It suffers from the same
limitation as the __new__ in that you can't pass configuration data to
the init.  But you can do a 'configure' class method, as you can also do
with __new__

Personally, I now prefer these: first place:

http://bitbucket.org/spookylukey/django-class-views-experiments/src/tip/classmethod.py

Close second:

http://bitbucket.org/spookylukey/django-class-views-experiments/src/tip/magicnew_with_configure.py

Given the limitations, I'm no longer that bothered about the fact that
the __new__ method returns something completely unexpected, but Alex's
classmethod solution seems like a nice improvement on it, though it
makes a URLconf very slightly more verbose.

Luke


-- 
"Doubt: In the battle between you and the world, bet on the world." 
(despair.com)

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.

Reply via email to