« XML Schema support on Zope 3 | Main | XML Schema support on Zope3 (Concret example) »

Aug 18, 2005

Extending products Zope3-style.

Today we had a need to extend the CPSSharedCalendar a little bit in a separate project. The functionality needed was not seen as generic enough to go into the CPSSharedCalendar itself. Luckily, since it's written with Five, this can be done easily, and without touching the original code, or monkey patching, and with none of the standard problems of using portal_skins. So I thought it might be interesting to show how this is done, as a way to convert more people to Zope3 and Five.

Basically, the project needed to display a list of events from the users calendar, but only the events from today, and with a custom formatting. Here is the rough steps used, as an example to show to others how to do it:

  • Create a new product. A folder under Products and an empty __init__.py is all that is needed.
  • Create a view class that has a method that performs the actions you need. Lets call the module customeventview.py, and the class CustomEventsView.
class CustomEventsView:
    "View for returning a list of all events of today"

    def getEvents(self):
        events = self.context.getTheEventsWhichIwant()
        return events
  • Create a template that calls the view class, and return the list of events as you want it, lets call it customevents.pt.
<html metal:use-macro="context/@@standard_macros/page">
  <metal:block fill-slot="body">
    <ul tal:define="events view/getEvents">
      <li tal:contents="event/title" />
    </ul>
  </metal:block>
</html>

  • Create a configure.zcml that connects the template to the view class.
<configure xmlns="http://namespaces.zope.org/zope"
           xmlns:browser="http://namespaces.zope.org/browser">

  <browser:page
    for="calcore.interfaces.ICalendar"
    name="customevents.html"
    template="customevents.pt"
    class=".customeventsview.CustomEventsView"
    permission="calendar.ViewCalendar"
    />

</configure>
This example, as you see, provides no great functionality. Only another, custom view. But the point here is that this customization is completely local, it does not require any modification of the original software, nor does it monkeypatch it. At the same time, should you want to, the customization is easy to move into the original product.

But, you say, this can be done by making a new skin in portal_skins! Sure, but then you run into problems of the restricted code of python scripts. This is all disk based, and has no such problems. Also, normally you would have to set up a custom skin folder for these overrides, and they have to be set up in the Zope site, while this type of Zope3/Five extension only needs you to copy the product into the Products folder and restart Zope. You don't need to run any installation scripts, or add any new skin folder to the list of folders in all the skins.

That's the power of Zope3 and Five.

(Post originally written by Lennart Regebro on the old Nuxeo blogs.)

Comments

About Us

We're the friendly employees of Nuxeo, a leading open source software vendor, which develops a complete Enterprise Content Management (ECM) software platform to help companies better produce, process, publish, archive, expose and find their information from digital assets to transactional documents.

» Follow us @nuxeo (Twitter)

» Connect on LinkedIn

» Visit Nuxeo.com

 

Customize & Configure
Nuxeo • Studio

Nuxeo • DM
Online Trial

Nuxeo • DM
Download

Nuxeo • DAM
Download

Nuxeo Connect support