Christopher Warner Studies and thoughts, usually in coherent fashion.

17Nov/073

Zope/Plone have changed my life

I can't stress enough how pleased I am with Zope/Plone in regards to a CMS system. If you are doing content management and are using Python then I strongly suggest you look at Zope/Plone. Python being such a strong and usable language that makes the impossible; possible and the architecture of Zope and the CMF Framework which Plone is built from makes it a CMS killer. Period. Which brings me to the reason for this entry.

Here at New York Magazine we have a fashion section. It's a mismash of Krang and other random Dreamweaver run around all over the place HTML. This is obviously no way to manage the content in this, the year, 2007. So I have begun to take on the process of breaking it down into Plone and came across the subscriber/event model system available in Zope3. It's great and here's a quick tutorial on how to use it.

A user is working with a Model Biography and the Fashion editor want's an IM when each Model Biography is created.

First we setup an interface (marker interface) for our Model Biography:
from zope.interface import Interface

class IModelBio(Interface):
""" Model Biography """

Think of the interface as documentation for the class, describing what it can and can't do. As this class doesn't have any methods there is just a comment describing that it's a Model Biography.

We then have the actual ModelBio class which implements our interface.

class ModelBio(BaseContent):

"""A Model Object """
implements(IModelBio)

From here we can now modify our configure.zcml (this configures Zope the way we want it), where we add our subscriber. Here is a good description of ZCML and why it gives our code more structure.

note: Do to the way WordPress filters html tag/close tag should be replaced with the appropriate markup. Seems I need to either upgrade or find some new blog software.

tag subscriber
for=".interfaces.IModelBio
Products.Archetypes.interfaces.IObjectInitializedEvent"
handler=".events.model_created"close tag

What this says is that for ModelBio we want to know when a ModelBio object is created. When we know that, events.model_created, will be handling said situation. So, all that's left to do is add a method called model_created in events.py

def model_created(model, event):
""" blah blah """
print model.title + " has been created"

That is pretty much it! Again, if you are doing CMS anything you may as well investigate Zope/Plone. I also highly recommend picking up a copy of Martin Aspeli's book; "Professional Plone Development", available here. It will definitely help, even if you are a beginner to Plone. Here's a recent review of the book on Slashdot. As usual the commentary on Slashdot is to be used as toilet paper. Needless to say I don't make a dime off of any of this the book is just that good.

About Christopher Warner

Christopher Warner is part genius, part idiot. This makes him well balanced. He's worked on numerous opensource projects with great people and has generally led an eventful and fulfilling life. He hopes to retire an old man in a rocking chair should he be so fortunate.
Comments (3) Trackbacks (0)
  1. about html opening/closing tag, try the html entities < and >

  2. sorry, the entities are rendered :)
    I mean &lt; and &gt;

  3. Thanks for the tip, hope this helped yah..


Leave a comment

You must be logged in to post a comment.

No trackbacks yet.