Don't know if this is applicable to you situation, but what I've done
when I want to use the manipulator to validate a subset of fields is
the following:

1. pass your copy of the POSTed data containing the subset of data you
want to validate to the manipulator as normal for validation. The
errors you get back will contain any error messages on the subset of
data you're interested in + errors on the other fields you want to
ignore.

2. Create a new "errors_subset" dict of your own and copy the errors
for the subset of fields you want to validate into this new dict.

3. Proceed as normal, but use your "errors_subset" dict in place of the
full "errors" dict.

Looks something like this:

    manipulator = applications.ChangeManipulator(a_id)

    detail_errors = {}
    errors = {}
    if request.POST:
        # got some sort of data posted from the detail view
        new_data = request.POST.copy()

        # check for errors against model data
        errors = manipulator.get_validation_errors(new_data)

        # convert data to python format
        manipulator.do_html2python(new_data)

        # first add in any errors found from standard model validation that
apply
        # to this situation
        model_error = errors.get('date_inspect',False)
        if model_error:
                detail_errors['date_inspect'] = model_error

        model_error = errors.get('inspect_agent',False)
        if model_error:
                detail_errors['inspect_agent'] = model_error

        model_error = errors.get('inspect_org',False)
        if model_error:
                detail_errors['inspect_org'] = model_error

        model_error = errors.get('inspect_notes',False)
        if model_error:
                detail_errors['inspect_notes'] = model_error

       # check for errors
       if not detail_errors:
                # save data to model

       ....

    form = formfields.FormWrapper(manipulator, new_data, detail_errors)

        .....

     # display template...

You get the idea - probably not the most elegant approach, but works.
Only downside is that you need to explicitly "know" what set of fields
to save and save each one at a time to the model. Alternatively, if the
other fields are not required, then you can pass the set of new_data to
the manipulator for a bulk save.

Chris

Reply via email to