Ticket #2757: docs.diff

File docs.diff, 3.0 KB (added by Gary Wilson <gary.wilson@…>, 9 years ago)
  • docs/forms.txt

     
    161161
    162162        # Check for validation errors
    163163        errors = manipulator.get_validation_errors(new_data)
     164        manipulator.do_html2python(new_data)
    164165        if errors:
    165166            return render_to_response('places/errors.html', {'errors': errors})
    166167        else:
    167             manipulator.do_html2python(new_data)
    168168            new_place = manipulator.save(new_data)
    169169            return HttpResponse("Place created: %s" % new_place)
    170170
     
    217217
    218218            # Check for errors.
    219219            errors = manipulator.get_validation_errors(new_data)
     220            manipulator.do_html2python(new_data)
    220221
    221222            if not errors:
    222223                # No errors. This means we can save the data!
    223                 manipulator.do_html2python(new_data)
    224224                new_place = manipulator.save(new_data)
    225225
    226226                # Redirect to the object's "edit" page. Always use a redirect
     
    312312        if request.POST:
    313313            new_data = request.POST.copy()
    314314            errors = manipulator.get_validation_errors(new_data)
     315            manipulator.do_html2python(new_data)
    315316            if not errors:
    316                 manipulator.do_html2python(new_data)
    317317                manipulator.save(new_data)
    318318
    319319                # Do a post-after-redirect so that reload works, etc.
     
    321321        else:
    322322            errors = {}
    323323            # This makes sure the form accurate represents the fields of the place.
    324             new_data = place.__dict__
     324            new_data = manipulator.flatten_data()
    325325
    326326        form = forms.FormWrapper(manipulator, new_data, errors)
    327327        return render_to_response('places/edit_form.html', {'form': form, 'place': place})
     
    336336    * ``ChangeManipulator.original_object`` stores the instance of the
    337337      object being edited.
    338338
    339     * We set ``new_data`` to the original object's ``__dict__``. This makes
    340       sure the form fields contain the current values of the object.
    341       ``FormWrapper`` does not modify ``new_data`` in any way, and templates
    342       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.
    343343
    344344    * The above example uses a different template, so create and edit can be
    345345      "skinned" differently if needed, but the form chunk itself is completely
     
    394394        if request.POST:
    395395            new_data = request.POST.copy()
    396396            errors = manipulator.get_validation_errors(new_data)
     397            manipulator.do_html2python(new_data)
    397398            if not errors:
    398                 manipulator.do_html2python(new_data)
    399 
    400399                # Send e-mail using new_data here...
    401400
    402401                return HttpResponseRedirect("/contact/thankyou/")
Back to Top