On 9/12/06, Adrian Holovaty <[EMAIL PROTECTED]> wrote: > > Hence, with this new API, the above view code would be written like this: > > form = ContactForm() > if request.method == 'POST' and form.is_valid(**request.POST): > send_email_and_redirect() > return render_to_response('email_form.html', {'form': > form.bind(**request.POST)})
Hmm... taking some ideas from Russ Magee, what about this: form = ContactForm() if request.method == POST and form.bind(request.POST): send_email_and_redirect() return render_to_response('email_form.html', {'form':form}) Assumptions: form.bind(data) does *not* return a BoundForm. bind does the validation and probably populates form.errors or .errors() or whatever. bind returns True or False depending on whether validation succeeded or not. bind does not short circuit on the first error. Validation happens only once, in the bind call. It's not entirely obvious that a method called bind would return a boolean depending on the success of validation, but examples and docs should clear that up that I think. Maybe this is being too clever to save a couple of lines or a few milliseconds though. Just for good measure, here's what it would look like to use a change form: address = Address.objects.get(address_id) form = AddressChangeForm(address) if request.method == POST and form.bind(request.POST): # save the object and return a redirect return render_to_response('email_form.html', {'form':form}) You pass the original object into the form constructor. The form values are then initialized with values from the original object. When you call bind, it overwrites the form values with the data passed to bind. Let me know if this doesn't make any sense. I may have forgotten to write down some essential assumptions. Joseph --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---