On Jul 15, 3:05 pm, "Scott Moonen" <[EMAIL PROTECTED]> wrote:
> Hi Victor,
>
> It sounds like your pattern works well for you, which is good.
>
> Another pattern that can be used is to have the view select off of some of
> the request attributes, and maybe even add your own test functions (such as
> "accepts()") to the request class.  For example:
>
> if request.accepts('application/xhtml+xml') : template_ext = "xhtml"
> elif request.is_ajax() : template_ext = "json"
> else : template_ext = "html"
> . . .

I think that's the kind of test I'd like to have in my decorator.
Thanks for the tip :)

> If you think about the broader uses of view functions, I think you may find
> that the apparent elegance of your approach breaks down.  You want the view
> functions to be agnostic of whatever output format they use, and I think
> that may be possible to achieve (although you create a little bit of
> overhead in constructing and passing variables for the template that aren't
> used for all output types).  However, another purpose of view functions is
> to process input and take corresponding action.  In cases like this I don't
> think you can avoid making the view functions much more intimately aware of
> the underlying format (e.g., AJAX or REST request versus vanilla HTTP
> POST).  This applies to how the input is parsed, but also to the subsequent
> action that is taken: for HTTP POST you may re-display a form on validation
> error, or else return a redirect on success to view the object; but for AJAX
> you will likely emit some Javascript that updates the page, either to note
> errors or to reflect a successful update.

I've pandered this problem a bit myself. As far as input goes, I think
AJAX can use POST, but yes, it could be a problem. For output, I'm
thinking about maybe making views return something a bit more advanced
than a dictionary of data. It wouldn't be as elegant, but if I return
classes like ValidationFailedResponse(data) or
SuccessfulFormSubmitResponse(data) to the decorator (I hate naming
stuff), it can use them to generate the appropriate HttpResponse. If
the format is JSON, it should return Http200 and render a template, if
it's HTML, redirect. Not as clean, but hopefully it's cleaner than the
other options...
--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to