Did not find a how-to for your problem?

Ask me to write the how-to post by writing to the mailing-list at cps-devel [@] lists [.] nuxeo [.] com or writing to me to joseluisdelarosa+cpshowto [@] gmail [.] com. Note: I'll keep all conversations on the official mailing list.

Friday, November 2, 2007

How to create directory entries programatically

However, it also is possible that you need to creat a few entries in a directory programmatically.
I explain a usecase:

- You have to create an entity, like a company, into the portal.
- You need to have a few users associated to that company, like a Manager, a Reviewer, etc.

The way to do it is simple:

0. Import necessary modules.

from Products.CMFCore.utils import getToolByName

1. Take the directory where you need to create the entries.

directories = getToolByName(context, 'portal_directories')
my_dir = directories['my_dir']

2. Create the entry.

my_entry = {'id' : 'my_id',
'name' : 'my_name',
'data' : 'some other data'}

3. Insert the entry.


It also be useful to create test data.