On 2 jun, 23:22, Luke Plant <l.plant...@cantab.net> wrote:
> On Wednesday 02 June 2010 16:08:24 Roald wrote:
> >     class View(HttpRequest):
> >         def __init__(self, request, *args, **kwargs):
> >             ...
> >             super(View, self).__init__(self.content())
> >         ...
>
> You mean:
>
>      class View(HttpResponse):
>          ...

That's what I meant, yes.

> One reason against this is it makes it harder to re-use other views
> from within the View.

I don't really understand what you mean. Do you mean re-using 'good'
old function-views?

> You are forced to mutate the 'self' instance of
> HttpResponse (or else use some nasty hack),

No nasty hacks, just mutate 'self' from inside its class instead of
from outside.

> rather than being able to
> simply return the HttpResponse that might be returned from a utility
> function or a sub-view.

The other options presented in this topic (using __call__, __new__ or
View.as_view) all have their drawbacks, and personally I think I like
__init__ best:
- the __call__-option requires a different interpretation of url
patterns
- the __new__-option is actually a hack, does unexpected things and
thus is less readable, and is I think more complex that the __init__-
option
- the static/class method option is not really an improvement over
global functions, and leads to url patterns with more 'boiler plate
code'
- the __init__-option is only as complex as any Django programmer
should understand.

But even if you think that using __init__ is more complex than writing
a utility function: no worries. Normally you will use it something
like this:

    class myview(View):
        template_file = 'myapp/template.html'

        @property
        def context_dict(self):
            return {'authenticated':
self.request.user.is_authenticated()}

... which you can hardly call complicated.

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