Well... we have just developed a CPS product to import a local directory to a CPS Site.
You can download it using this svn url:
http://svn2.yerbabuena.es/pub/products/cps/CPSFileImporter/trunk
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.
Tuesday, January 15, 2008
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.
1. Take the directory where you need to create the entries.
2. Create the entry.
3. Insert the entry.
It also be useful to create test data.
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.
my_dir.createEntry(my_entry)
It also be useful to create test data.
Friday, October 12, 2007
How to create documents programatically
Sometimes you will need to create content programatically, a clear use case is to create default content in the member area. Let's suppose that you need to create a blog in each member area when the member area is created. There's a script called createMemberContent.py that can be customized for this issue.
As homework, how would you do it to give to the blog a more descriptive title, say "Blog of Alan Turing". Of course, where "Alan Turing" is the name of the owner of the blog ;-).
- Search for the createMemberContent.py in the portal_skins tool and click "Customized" or create a new file for it in your product's skins folder.
- The parameters of the createMemberContent.py script are:
- member: An object with the current member data of the autenthicated user, i.e. the owner of the new member area.
- member_id: The identifier of the member in string format.
- member_folder: A proxy to the member area where content will be created.
- member: An object with the current member data of the autenthicated user, i.e. the owner of the new member area.
- Given those parameters, the content of the script should be:
blog_id = 'blog'
member_folder.invokeFactory('Blog', blog_id)
blogProxy = getattr(member_folder, _id)
# Give permission to view the blog to all authenticated members
blogProxy.manage_setLocalGroupRoles('role:Authenticated', ('BlogReader',))
# Edit the document with valid information.
blog = docProxy.getEditableContent()
blogDef = {'Title': 'Blog'}
blog.edit(blogDef, blogProxy) - Go to the directory members and create a new member with private member area allowed.
- Log in the site and check that the blog has been created in the member area.
As homework, how would you do it to give to the blog a more descriptive title, say "Blog of Alan Turing". Of course, where "Alan Turing" is the name of the owner of the blog ;-).
Subscribe to:
Posts (Atom)