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.

Thursday, June 14, 2007

How to import skins folders

This post will put the tool portal_skins of CMF to work for the product CPSMessages.

In CMF the folders called skins are folders that have python scripts and Zope's page templates that can be called from whichever URL of the server.

To add the skins tool feature to the product CPSMessages the process is this:

  1. Add a file called skins.xml to the folder CPSMessages/profiles/default. The text of the file should look like this:



    <?xml version="1.0"?>
    <object name="portal_skins" meta_type="CMF Skins Tool">
    <object name="messages_default" meta_type="Filesystem Directory View"
    directory="CPSMessages/skins/messages_default"/>
    <skin-path name="CPSSkins">
    <layer name="messages_default" insert-after="custom"/>
    </skin-path>
    <skin-path name="CPSSkins-macroless">
    <layer name="messages_default" insert-after="custom"/>
    </skin-path>
    </object>



  2. Add a new step to the file CPSMessages/profiles/default/import_steps.xml with this content:



    <import-step id="skins" version="20040630-01"
    handler="Products.CMFCore.exportimport.skins.importSkinsTool"
    title="Skins Tool">
    <dependency step="toolset"/>
    Import skins tool's filesystem directory views and skin path definitions.
    </import-step>



  3. Create a folder in the path CPSMessages/skins/messages_default.

  4. In the folder created in step 3, add a file called hello_skins.zpt with these words in it:



    <p i18n:translate="hello_skins_imported">
    Hello, skins were imported sucessfully!
    </p>



  5. Register the skins directory so that Zope can access to its content. The way to do it is to add these two lines to the file CPSMessages/__init__.py.



    from Products.CMFCore.DirectoryView import registerDirectory
    registerDirectory('skins', globals())



  6. Restart Zope. The restart is needed because __init__.py file changed.

  7. Go to the tab Import of the tool portal_setup and check the step called Skins tool. Make sure that CPSMessages is the chosen profile in the combo box titled Profile and click the button “Import selected steps”.

  8. In the tool portal_skins you should see a folder called messages_default and after clicking on it, an object called hello_skins should be in there (notice that the extension is ommited). Click on the object hello_skins and use the tab “Test” to see it in action.
And that's all for today... As you may guess, the folder messages_default will be used to store python scripts, Zope's page templates, images and whatever resource that may be needed in the server. Notice the code in python scripts and ZPT in skins is restricted due to security reasons. If you need to write a file to filesystem or want to make system calls use methods in classes, e.g. tools (CPSMessages/MessagesTool.py).

Questions? Please, leave a comment ;-)

No comments: