• Ratings

last modified March 31, 2008 by miziodel

Summary

Plone contents are getting a nice new service to get them rated as needed by their users.

Alec improved the existing contentratings product introducing nice new features and power. You can check what's going on here:

  • http://svn.plone.org/svn/collective/contentratings/branches/multi-rating/
  • http://svn.plone.org/svn/collective/plone.contentratings/trunk/

What's New

plone.contentratings let's you use the now (nearly) pure zope3 package contentratings into plone. Let's talk about what's new in the base package:

  • We now have multi-ratings adapter(s) which let you create more than one named rating category adapter
  • The rating categories use TALES expressions instead of simple permissions to determine when ratings can be viewed or set. This allows much richer behavior, and easier compatibility with both Plone/CMF/Zope2 and various Zope 3 frameworks.
  • The rating categories can specify custom storage components and rating APIs. The user rating and editorial rating APIs remain the same, but more APIs can be added custom storages can be used for any API.
  • A view which combines all the rating categories available is provided. Base rating views for the included rating types are provided, and can be easily customized
  • A customizable utility is provided for efficiently creating and checking anonymous session IDs
  • A migration mechanism is provided to assist in moving between different storage implementations

The new plone.contentratings package provides:

  • A new control panel configlet to choose per portal_type which categories you want to activate.
  • A new control panel configlet panel to create and manage local rating categories for the portal TTW (we plan to allow folder level configuration as well)
  • UI for disabling ratings on specific content objects
  • Highly polished AJAX rating mechanism
  • A viewlet to display assigned rating categories in the content view

A quick example for our final case

Imagine you want to let Plone registered users rate both the author and quality of content Pages, but just want Reviewers to be able to have a look at the final rating results.

Here's what a portal manager needs to do to make this happen:

  • Install the contentratings package in Plone Control Panel.
  • A new configlet will appear called “Content Ratings”.
  • In the “Manage Categories” tab click the Add Local Categories button, fill in Title with “Rate this author”, Read expression with “python:checkPermission(Review portal content, context)”, and Write expression with “nocall:user”, and select the view you prefer.
  • Do the same for a second category titled “Rate this Page”.
  • Click the save button (this is VERY important!).
  • Click the Portal Types Categories tab.
  • Select “Page” portal type and choose your brand new categories in the multi-select.
  • Click the save button.

You will now find your ratings on every page in your site. Enjoy.

NB: if you'd like to turn off the rating on any specific page, just go to the settings tab on the edit form of that page and uncheck the Enable Ratings option.

Adopt your own rating vocabulary

To create a category with your own rating vocabulary is as easy as defining a vocabulary in your package and a browser view subclassing one of the views provided by contentratings, and setting there the “vocab_name“ properly.

let's create weird_rating.py:

      from zope.i18nmessageid import MessageFactory
      _ = MessageFactory('weirdpackage')
      from contentratings.browser.base_vocabs import titled_vocab
      from contentratings.browser.basic import BasicUserRatingView

      weird_vocab = titled_vocab1( (
                                   (1, _(u'Newbie') ),
                                   (2, _(u'Practical') ),
                                   (3, _(u'DragonballZ') )
                                  ) )
      class WeirdUserRating(BasicUserRatingView):
          “““A weird view that specifies weird terms“““
          vocab_name='weirdpackage.weird_vocab'

of course register it as needed in weirdpackage's configure.zcml:

        <configure xmlns=“http://namespaces.zope.org/browser“
                   xmlns:zope=“http://namespaces.zope.org/zope“
                   i18n_domain=“weirdpackage“>
           <page
               for=“contentratings.interfaces.IUserRating“
               name=“weird_user_rating“
               class=“.weird_rating.WeirdUserRating“
               template=“my_weird_rating.pt“   [..you can imagine how fancy this pt is :)]
               permission=“zope.Public“
               allowed_attributes=“rate remove_rating“
               />
           <zope:utility
               name=“weirdpackage.weird_vocab“
               component=“.weird_rating.weird_vocab“
               />
        </configure>
­

NB: add global categories and Storage stories..

Notes

Much of the sprinting time was spent “struggling” with the formlib machinery. It was very difficult to display individual form elements based on conditions.

It appears z3c.form would make this sort of customization much easier. We did not use it because the Plone configlet base classes are dependent on formlib.

KSS made it very easy to apply dynamic AJAX behaviour to both the rating and configlet UI.

archetypes.schemaextender allowed us to easily add an integrated UI for configuring ratings on each instance.

What Next

We need some more advanced reporting features on content ratings, e. g. “most rated” or “last rating user”.

To make this possible we will improve the indexing and reporting story.

Using Generic Setup to import and export categories would also be nice.

The way contentratings is registering local categories will easily let to implement a per folder based portal_types and category manager. MrTopf's new plone.localconf package may be useful here.

For now, plone.contentratings is lacking a complete unit and browser test suite, any contributions are welcome.

It may also be interesting to have a rating portlet for Plone to apply based on context, reference or portal base.

We need much more detailed documentation both for developers and integrators, to let them harness the full power of contentratings.

Parental Advisory: try not to use contentratings as a complete assessment framework!! :p