Personal tools
You are here: Home Weblog Archive 2006 October 22 Bulk modifying AT content fields under restricted python scripts
Document Actions
  • Send this page to somebody
  • Print this page
  • Add Bookmarklet

Bulk modifying AT content fields under restricted python scripts

by tibi last modified 2006-10-22 06:27
Filed Under:

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.

Weblog
Atom
RDF
RSS 2.0
Powered by Quills
Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 License.
 

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: