Ticket #2757: docs.diff
File docs.diff, 3.0 KB (added by , 18 years ago) |
---|
-
docs/forms.txt
161 161 162 162 # Check for validation errors 163 163 errors = manipulator.get_validation_errors(new_data) 164 manipulator.do_html2python(new_data) 164 165 if errors: 165 166 return render_to_response('places/errors.html', {'errors': errors}) 166 167 else: 167 manipulator.do_html2python(new_data)168 168 new_place = manipulator.save(new_data) 169 169 return HttpResponse("Place created: %s" % new_place) 170 170 … … 217 217 218 218 # Check for errors. 219 219 errors = manipulator.get_validation_errors(new_data) 220 manipulator.do_html2python(new_data) 220 221 221 222 if not errors: 222 223 # No errors. This means we can save the data! 223 manipulator.do_html2python(new_data)224 224 new_place = manipulator.save(new_data) 225 225 226 226 # Redirect to the object's "edit" page. Always use a redirect … … 312 312 if request.POST: 313 313 new_data = request.POST.copy() 314 314 errors = manipulator.get_validation_errors(new_data) 315 manipulator.do_html2python(new_data) 315 316 if not errors: 316 manipulator.do_html2python(new_data)317 317 manipulator.save(new_data) 318 318 319 319 # Do a post-after-redirect so that reload works, etc. … … 321 321 else: 322 322 errors = {} 323 323 # This makes sure the form accurate represents the fields of the place. 324 new_data = place.__dict__324 new_data = manipulator.flatten_data() 325 325 326 326 form = forms.FormWrapper(manipulator, new_data, errors) 327 327 return render_to_response('places/edit_form.html', {'form': form, 'place': place}) … … 336 336 * ``ChangeManipulator.original_object`` stores the instance of the 337 337 object being edited. 338 338 339 * We set ``new_data`` to the original object's ``__dict__``. This makes340 sure the form fields contain the current values of the object.341 ``FormWrapper`` does not modify ``new_data`` in any way, and templates342 cannot, so this is perfectly safe.339 * We set ``new_data`` to a "flattened" version of the original object's 340 data. This makes sure the form fields contain the current values of the 341 object. ``FormWrapper`` does not modify ``new_data`` in any way, and 342 templates cannot, so this is perfectly safe. 343 343 344 344 * The above example uses a different template, so create and edit can be 345 345 "skinned" differently if needed, but the form chunk itself is completely … … 394 394 if request.POST: 395 395 new_data = request.POST.copy() 396 396 errors = manipulator.get_validation_errors(new_data) 397 manipulator.do_html2python(new_data) 397 398 if not errors: 398 manipulator.do_html2python(new_data)399 400 399 # Send e-mail using new_data here... 401 400 402 401 return HttpResponseRedirect("/contact/thankyou/")