O'Reilly logo

Professional Plone Development: Building robust, content-centric web applications with Plone 3, an open source Content Management System by Martin Aspeli

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Forms in Viewlets

Finally, let us consider how to use forms in a generic viewlet. In Chapter 2, we presented the requirement to allow users to rate films. To manage film ratings, we have added an IRatings interface to interfaces.py in optilux.cinemacontent:

class IRatings(Interface):
    """An object which can be rated
    """
    score = schema.Int(title=_(u"A score from 1-100"),
                       readonly=True)
    def available(user_token):
        """Whether or not rating is available for the given user
        """
    def rate(user_token, positive):
        """Give a positive (True) or negative (False) vote.
        """

In ratings.py, there is an adapter from IFilm to IRatings, which stores ratings in annotations on a Film object. We will not reproduce that code here, but take a look at the class and its doctest ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required