Personal tools
You are here: Home Products garbas.contentrating Documentation How to integrate content rating for your custom type
Document Actions

integrate content rating for your custom type

This How-to applies to: Any version.

how to integrate garbas.contentrating into your custom content types

following howto was mostly copied from http://plone.org/products/contentratings. it was also fixed and updated to work with Plone3 and garbas.contentrating.

This is a simple python product driven by Zope 3, which is intended to make it easy to let users (optionally including anonymous) or editors rate content. It provides a set of interfaces, adapters and views to allow the application of ratings to any IAnnotatable object.

Install

There are many ways how to install zope3 package. One of them is build out. So if you have something like this in your buildout.cfg you are going the right way:

# Add additional eggs here
# elementtree is required by Plone
eggs =
    elementtree
    ...
    garbas.contentrating
    ...

Bounding rating to your custom content type

If you want to allow some content to be rated you must mark it as both ratable and annotatable. The standard way to do this is to add the following to your product's configure.zcml:

<class class=".content.MyContentClass">
  <implements
      interface="garbas.contentrating.interfaces.IEditorRatable
                 zope.app.annotation.interfaces.IAttributeAnnotatable"
      />
</class>

If you want the content to be UserRatable instead of or in addition to being Editor ratable you just add garbas.contentrating.interfaces.IUserRatable to the interface declaration:

<class class=".content.MyContentClass">
  <implements
      interface="garbas.contentrating.interfaces.IUserRatable
                 zope.app.annotation.interfaces.IAttributeAnnotatable"
      />
</class>

Or you can also apply both type of content ratings:

<class class=".content.MyContentClass">
  <implements
      interface="garbas.contentrating.interfaces.IEditorRatable
                 garbas.contentrating.interfaces.IUserRatable
                 zope.app.annotation.interfaces.IAttributeAnnotatable"
      />
</class>

Permissions

To determine who gets to rate content and view ratings there are a few permissions listed below (with their Zope2 equivalents in parentheses):

contentratings.EditorRate (Content Ratings: Editor Rate)
contentratings.ViewEditorialRating (Content Ratings: View Editorial Rating)
contentratings.UserRate (Content Ratings: User Rate)
contentratings.ViewUserRating (Content Ratings: View User Rating)

For example to disallow anonymous users from rate objects, just remove the contentratings.UserRate permission from Anonymous in the ZMI. By default Anonymous is granted UserRate and all the viewing Permissions, and Reviewer and Manager are granted the EditorRate permission.

 

Using the Views

To include the views in your page layout just include the following snippet in your template:

<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:editorialrating>
<span tal:replace="structure context/@@user_rating_view|nothing" />
<span tal:replace="structure context/@@user_rating_set|nothing" />

Including this at the end of Plone's document_byline.pt, for example, would be appropriate. It will only display ratings when the current content is ratable and the user has permission to view them. If the user has permission to edit the rating then the edit mode will be shown below the current rating for User ratings, or shown instead to the current rating for Editorial ratings.

 

 

 

 

 

 

 

 

by Rok Garbas last modified February 20, 2008 - 22:00

For any issues with the web site functionality, please file a ticket.

Please consult the policy on plone.org content if you want your content published on this site.

Servers and hosting by