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.

Wednesday, June 6, 2007

How to create a tool

  1. Create a file MessagesTool.py in the folder CPSMessages like this:


    # Python modules
    import logging

    # Third-party modules
    from OFS.SimpleItem import SimpleItem

    # This product's modules

    # Global variables

    logger = logging.getLogger('CPSMessages.MessagesTool')

    class MessagesTool(SimpleItem):
    ”””
    ”””
    id = "portal_imessages"
    meta_type = "MessagesTool"



  2. Register the tool in the file __init__.py of the product by adding the import of the class ToolInit and the ToolInit method to initialize procedure.



    from Products.CMFCore.utils import ToolInit

    import MessagesTool

    def initialize(context):
    """
    """

    ToolInit(
    'Messages Tool',
    tools=(MessagesTool.MessagesTool,),
    icon='tool.png',).initialize(context)



    The class ToolInit needs the name of the new tool, a list of tools to register and the filename of an icon.

  3. Copy the icon called tool.png from any other product or create your own, it can be a .gif too.


  4. Add a new step in the file import_steps.xml (path CPSMessages/profiles/default) to import tools. The new file looks like this:


    <?xml version="1.0"?>
    <import-steps>
    <import-step id="toolset" version="20040630-01"
    handler="Products.GenericSetup.tool.importToolset"
    title="Required tools">
    Create required tools, replacing any of the wrong class, and remove
    forbidden ones.
    </import-step>
    </import-steps>



  5. Create a new file toolset.xml (path CPSMessages/profiles/default)


    <?xml version="1.0"?>
    <tool-setup>
    <required tool_id="portal_imessages"
    class="Products.CPSMessages.MessagesTool.MessagesTool"/>
    </tool-setup>


  6. Restart Zope and import the profile CPS Messages from the ZMI in the tool portal_setup. The new tool portal_imessages should be available from the root of the CPS instance.

Note: The identifier of the tool is portal_imessages and not portal_messages due to a conflict of names. CPSSkins uses a tool called portal_messages for internationalization stuff.

Did you enjoy this post? Leave a comment please, even if you didn't enjoyed! Thanks ;-)

1 comment:

Johnny Lake said...

Good job man !!! I encourage you to continue working on this tips.