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, 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.

  1. 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.
  2. 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.


  3. 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)

  4. Go to the directory members and create a new member with private member area allowed.
  5. 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 ;-).

Thursday, September 6, 2007

How to put colored styles to rows in a table

Put this line into a <tr> tag:


tal:attributes="class python:test(repeat['item'].even(), 'even ajaxtd', 'odd ajaxtd')"


and you'll have an amusing table... with the same style that any others in your portal.

Monday, August 6, 2007

How to change the colour of the portal status message

An interesting feature of CPS, from the point of view of a developer, is how dynamic generation CSS is implemented.

One of the main reasons to face rendering of CSS is when you need to change the background colour of the portal status message, as its colour can't be changed from themes manager style definitions. To change the styles of the portal status message do this:

  1. Go to the ZMI
  2. Go to the tab Find of portal_skins.
  3. Search for the identifier stylesheet_properties
  4. Click the one file listed that has a red asterisk (this means that's the one that is being used by Zope).
  5. Click the button "Customize".
  6. Search for the property messageBackground and change its default value (#ffca31) for the new one that suits your design.
Look around for other properties that may be changed this object has some other CSS properties that may not be changed from themes management screen.

If you want to know a little more about how CPS uses these properties, do again a search for the file default.css and you will see that the code is in fact DTML which uses stylesheet_properties as variables inside CSS definitions.

And that's all for now, I hope it helps ;-)