A thought on methods in Plone
This was originally posted on blogger here.
We just did a sprint on our big project at work. My first step was to create a bunch of methods in the content types that would traverse between items via the reference catalog (yes Virginia, we are using the Relations product along with Association Classes
Our first thought was to return a
tuple of the title, description, and url of the referred item. Well, that turned out to be annoying because:
is not as much fun as:
Also, for the graphic designers, having them start typing '
python:' everywhere just seemed like fighting a battle we didn't need to fight.
Then we decided to return a dictionary containing title, url, and description. And in some cases, acronym, image, and more. Now we have:
Hooray! Except that there are about 10+ and growing examples now of times when we missed something that needed to be returned.
So it hit me, why not just return the darn catalog brain? Sure,
reference_catalog doesn't return a usable URL (you have to strip off the
/at_reference/md5_hash), but I've already written an often reused python script that does this called
cleanUrl. If we went this method, we get:
And if we hit another snag where we need to also return field x, y, and z, we have them do this:
<div define="item python:itemBrain.getObject()" content="item/funnyQuote"></div>
Tags: plone zope legacy-blogger