On 03-09-11 16:05, Luke Plant wrote:
The history of CBVs in Django is that they are simply a way of using OOP
and inheritance to reduce duplication between view functions and allow
better re-use. They are supposed to be drop in replacements for function
based views in terms of the end result, rather than produce any change
in what a template will contain.

Ok, when you want to keep the function and class based views more or less the same, the current implementation makes sense.

On the other hand, from an object oriented viewpoint, the class based views seem to be pretty powerless and non-object-oriented. To me, it almost seems like they're artificially "castrated" to make function views look good :-) That's probably not the intention, but...

Probably the best illustration of my point: .get_context_data() should return a dictionary. And .render_to_response() needs the output of that. "So" you have to pass the output of .get_context_data() to .render_to_response(). Wait a minute... We're talking object orientation here! Why doesn't .render_to_response() call .get_context_data()? This is just function-like behaviour in a thin object oriented shell.

From an OO viewpoint, I'd rather expect a "self.context = {}" in the most top-level view baseclass's __init__(). Not passing along a variable that is calculated in the very same class as a parameter to a method in that very same class.


Your point that, effectively, {{ view.something }} is different than {{ something}} is valid, though. In that sense, a class based view that passes {'view': self} as the context dict isn't a drop-in replacement.

Would you be more happy with a more magical view that would inject everything from local() into the context dictionary or something like that?


Reinout

--
Reinout van Rees                    http://reinout.vanrees.org/
rein...@vanrees.org             http://www.nelen-schuurmans.nl/
"If you're not sure what to do, make something. -- Paul Graham"

--
You received this message because you are subscribed to the Google Groups "Django 
developers" group.
To post to this group, send email to django-developers@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