On 8/24/06, James Bennett <[EMAIL PROTECTED]> wrote:
>
> On 8/23/06, Brantley Harris <[EMAIL PROTECTED]> wrote:
> > The problem is that to make it usefull to the user (read: api-user /
> > developer), you have to put the model save in a try / except block so
> > that if there is a validation error, it can raise the form.
> > Otherwise, the user will have to provide their own try / except block.
>
> If I'm reading the example on the wiki correctly, you'd already need
> to do this in your view -- the difference is whether the try/except
> wraps around 'manipulator.process' or 'manipulator.save', and though
> it's mainly semantics, I think the latter is preferable.

No, watch for the difference between a ValidationError being raised
and a Form exception being raised.  In the ValidationError case, it
must be saved and returned with the other validation errors in the
given step (1. conversion; 2. form validation; 3. model validation),
and then finally a Form exception must be raised.

Check out the ._save() function in the Manipulator.  It wraps the user
provided .save(), and catches the ValidationError and raises a Form.
Come to think about it, ValidationError really should be
ValidationErrors, with an s.  If at all possible we should get as many
errors out as we can to give to the form-user.  That's why I pick out
those three steps above; no later step can go forward, or even check
for errors, before the previous steps are complete.

I did play with:
    m = Manipulator(request.POST)
    m.save()

That has some merit, I think.  But again, the user would have to
provide a try / except block. Something like this:

try:
     m = Manipulator(request.POST)
     m.save()
except ValidationErrors, errors:
     render_to_response('polls/create.html', {'form': m.get_form(errors)})

Not very pretty...

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

Reply via email to