Bulk modifying AT content fields under restricted python scripts

I'm working on a project that mostly extends an older, legacy based Plone 2.0 project. This project has a CMFFormController form with about 20 fields and based on that input needs to create new AT content items, which is done in the action script of the controller chain. To achieve this, I have the following code:

First, I have a field_mapping that maps the fields from the form to the AT field names. Based on this mapping, I'm retrieving the value from REQUEST and set it back in the mapping (the form generation changes the field names to concatenate with a session id, in order to save the already submited values in a session, as far as I understand).

    #write the values into the above dict
    for key in field_mapping:  
        field = request.get('%s_%s' % (field_mapping[key], sid))
        field_mapping[key] = field

The form also has some field upload fields, which I'm handling with this code:

    #handle the empty file uploads
    for f in ['file1', 'file2', 'file3']:
        fupload = request.get(f, None)
        fname = getattr(fupload, 'filename', '')
        if fname.strip() <> '':
            field_mapping[f] = fupload

In the end, I'm calling the mutators for each field to set the values to those retrieved from REQUEST.   Calling Schema[fieldname].set() is impossible to do from the restricted Python script because of the security settings.

    schema = myobj.Schema()
    for fname in field_mapping:
        field = schema[fname]
        mutator = field.getMutator(proposal)
        mutator(field_mapping[fname] )

I've first tried to pass the field_mapping as **field_mapping argument to the plone_utils.contentEdit method, but it doesn't seem to update AT based objects, just the attributes.

Comments