Rating content in a Plone site
I’ve been meaning to try out Alec Mitchell’s contentratings product and tonight I finally sat down and tried installing it in a fresh Plone 2.5 test instance. The README is very comprehensive, but apparently I didn’t read it carefully enough because after putting contentratings into the Zope products directly, Zope wouldn’t restart.
Alec was on the #plone IRC channel and was kind enough to walk me through the process of configuring it. The product uses the “new school” approach which is to put it in $INSTANCE/lib/python. Once I moved it there, then Zope started up with no problem.
The next instructions in the README were to add the interface declarations in configure.zcml. Since I was just testing the product, I decided to configure as rateable the ‘Page’ content type that comes with ATContentTypes. This required adding these lines to ATContentTypes/configure.zcml:
1 2 3 4 5 6 7 8 9 10 11 12 |
<code> <content class=".content.document.ATDocument"> <implements interface="contentratings.interfaces.IEditorRatable zope.app.annotation.interfaces.IAttributeAnnotatable" /> <implements interface="contentratings.interfaces.IUserRatable zope.app.annotation.interfaces.IAttributeAnnotatable" /> </content> </code> |
After reporting that this still wasn’t working, Alec realized that he had omitted one critical line in configure.zcml:
1 2 3 |
<code> <include package="contentratings" /> </code> |
Then I added the following code snippet to the bottom of CMFPlone/skins/plone_content/document_byline.pt:
1 2 3 4 5 6 7 8 9 10 |
<code> <tal:editorialrating tal:define="edit_rating context/@@editorial_rating_set|nothing"> <span tal:condition="edit_rating" tal:replace="structure edit_rating" /> <span tal:condition="not:edit_rating" tal:replace="structure context/@@editorial_rating_view|nothing"/> </tal> <span tal:replace="structure context/@@user_rating_view|nothing" /> <span tal:replace="structure context/@@user_rating_set|nothing" /> </code> |
Lastly, it was necessary to add these lines to the configure.zcml file to get the star images to appear:
1 2 3 4 5 |
<code> <five:traversable class="OFS.Application.Application" /> <five:traversable class="Products.CMFCore.PortalObject.PortalObjectBase" /> </code> |
The last line is not necessary if you are using Plone 2.5, since everything is already traversable.
What next
I proposed making a simple product which configures the relevant content types to be ratable, adds the indexes to the catalog and provides some nice looking views and portlets to display the highest rated content on the site.
I asked about making a configlet which would let the site admin choose which content types were ratable and Alec’s reply was “you just make a view that calls classImplements on the classes or directlyProvides on the instances.”
The goal is to make contentratings accessible and usable out-of-the-box. This could be a nice little weekend project.
Recent Comments