Exemplo n.º 1
0
class ICategoryDirective(IRatingCategoryInfo):
    """Describes a rating category"""
    for_ = zope.configuration.fields.GlobalObject(
        title=_("Specifications of the object to be rated"),
        description=_("This should be a single interface or class"),
        required=True,
    )
    storage = zope.configuration.fields.GlobalObject(
        title=_("The dotted path to the storage factory"),
        description=_(
            "This is the persistent class used for storing ratings."),
        required=False,
    )
Exemplo n.º 2
0
 def remove_rating(self, redirect=True):
     """Remove the rating for the current user"""
     context = self.context
     userid = context.userid
     if userid:
         context.remove_rating(userid)
     return self._redirect(redirect, msg=_(u"You have removed your rating"))
Exemplo n.º 3
0
 def remove_rating(self, redirect=True):
     """Remove the rating for the current user"""
     context = self.context
     userid = context.userid
     if userid:
         context.remove_rating(userid)
     return self._redirect(redirect, msg=_(u'You have removed your rating'))
Exemplo n.º 4
0
    def rate(self, value, redirect=True):
        """Rate the content.  Enforce vocabulary values.
        """
        assert int(value) in self.vocabulary
        msg = _(u'The rating has been changed')

        self.context.rating = value
        return self._redirect(redirect, msg=msg)
Exemplo n.º 5
0
    def rate(self, value, redirect=True):
        """Rate the content.  Enforce vocabulary values.
        """
        assert int(value) in self.vocabulary
        msg = _(u'The rating has been changed')

        self.context.rating = value
        return self._redirect(redirect, msg=msg)
Exemplo n.º 6
0
 def rate(self, value, redirect=True):
     """Rate the content.  Enforce vocabulary values.
     """
     assert int(value) in self.vocabulary
     context = self.context
     userid = context.userid
     msg = _(u'You have changed your rating')
     if userid is None and not self.can_rate:
         return self._redirect(redirect,
                               msg=_(u'You have already rated this '
                                     u'item, and cannot change your '
                                     u'rating unless you log in.'))
     elif userid is None:
         # rate the object passing in the session id
         context.rate(value, session_key=self._session_key)
     else:
         context.rate(value, userid)
     return self._redirect(redirect, msg=msg)
Exemplo n.º 7
0
 def post_rate(self, orig_url=None):
     if orig_url is not None:
         message = '%s' % _('You have changed your rating').decode('utf-8')
         q_spacer= '?' in orig_url and '&' or '?'
         messages = IStatusMessage(self.request, alternate=None)
         if messages is not None:
             messages.addStatusMessage(message, 'info')
         res = self.request.RESPONSE
         return res.redirect(orig_url+q_spacer)
Exemplo n.º 8
0
 def post_rate(self, orig_url=None):
     if orig_url is not None:
         message = '%s' % _('You have changed your rating').decode('utf-8')
         q_spacer = '?' in orig_url and '&' or '?'
         messages = IStatusMessage(self.request, alternate=None)
         if messages is not None:
             messages.addStatusMessage(message, 'info')
         res = self.request.RESPONSE
         return res.redirect(orig_url + q_spacer)
Exemplo n.º 9
0
 def rate(self, value, redirect=False):
     """Rate the content.  Enforce vocabulary values.
     """
     assert int(value) in self.vocabulary
     context = self.context
     userid = context.userid
     msg = _(u'You have changed your rating')
     if userid is None and not self.can_rate:
         return self._redirect(redirect,
                               msg=_(u'You have already rated this '
                                     u'item, and cannot change your '
                                     u'rating unless you log in.'))
     elif userid is None:
         # rate the object passing in the session id
         context.rate(value, session_key=self._session_key)
     else:
         context.rate(value, userid)
     return self._redirect(redirect, msg=msg)
Exemplo n.º 10
0
    def rate(self, value, redirect=True):
        """Rate the content.  Enforce vocabulary values.
        """
        try:
            value = int(value)
            if value not in self.vocabulary:
                raise ValueError()
        except ValueError:
            raise BadRequest("Invalid rating value")

        msg = _(u'The rating has been changed')

        self.context.rating = value
        return self._redirect(redirect, msg=msg)
Exemplo n.º 11
0
    def rate(self, value, redirect=True):
        """Rate the content.  Enforce vocabulary values.
        """
        try:
            value = int(value)
            if value not in self.vocabulary:
                raise ValueError()
        except ValueError:
            raise BadRequest("Invalid rating value")

        msg = _(u"The rating has been changed")

        self.context.rating = value
        return self._redirect(redirect, msg=msg)
Exemplo n.º 12
0
    def rate(self, value, redirect=True):
        """Rate the content.  Enforce vocabulary values.
        """
        try:
            value = int(value)
            if value not in self.vocabulary:
                raise ValueError()
        except ValueError:
            raise BadRequest("Invalid rating value")

        context = self.context
        userid = context.userid
        msg = _(u"You have changed your rating")
        if userid is None and not self.can_rate:
            return self._redirect(
                redirect,
                msg=_(u"You have already rated this " u"item, and cannot change your " u"rating unless you log in."),
            )
        elif userid is None:
            # rate the object passing in the session id
            context.rate(value, session_key=self._session_key)
        else:
            context.rate(value, userid)
        return self._redirect(redirect, msg=msg)
Exemplo n.º 13
0
    def rate(self, value, redirect=True):
        """Rate the content.  Enforce vocabulary values.
        """
        try:
            value = int(value)
            if value not in self.vocabulary:
                raise ValueError()
        except ValueError:
            raise BadRequest("Invalid rating value")

        context = self.context
        userid = context.userid
        msg = _(u'You have changed your rating')
        if userid is None and not self.can_rate:
            return self._redirect(redirect,
                                  msg=_(u'You have already rated this '
                                        u'item, and cannot change your '
                                        u'rating unless you log in.'))
        elif userid is None:
            # rate the object passing in the session id
            context.rate(value, session_key=self._session_key)
        else:
            context.rate(value, userid)
        return self._redirect(redirect, msg=msg)
Exemplo n.º 14
0
from zope.schema.vocabulary import SimpleTerm, SimpleVocabulary
from contentratings.interfaces import _


def titled_vocab(items):
    terms = [SimpleTerm(k, title=v) for k,v in items]
    return SimpleVocabulary(terms)

five_star_vocab = titled_vocab(((1, _(u'Poor')),
                          (2, _(u'Fair')),
                          (3, _(u'Good')),
                          (4, _(u'Very Good')),
                          (5, _(u'Excellent'))))

three_star_vocab = titled_vocab(((1, _(u'Unacceptable')),
                                 (2, _(u'Acceptable')),
                                 (3, _(u'Excellent'))))

Exemplo n.º 15
0
from contentratings.category import RatingsCategoryFactory, BASE_KEY
from contentratings.interfaces import _
from contentratings.permissions import (
    EditorRate,
    ViewEditorialRating,
    UserRate,
    ViewUserRating,
)
from contentratings.storage import EditorialRatingStorage, SINGLEKEY

# A Plone-y permission expression since these classes are just for BBB with
# Plone products
PERM_EXPR = ("python:getattr(getattr(context, 'portal_membership' ,None),"
             " 'checkPermission', lambda *x: True)('%s',"
             " context)")
EditorialRatingCat = RatingsCategoryFactory(_(u'Editor Rating'),
                                            read_expr=PERM_EXPR %
                                            ViewEditorialRating,
                                            write_expr=PERM_EXPR % EditorRate,
                                            storage=EditorialRatingStorage)
UserRatingCat = RatingsCategoryFactory(_(u'User Rating'),
                                       read_expr=PERM_EXPR % ViewUserRating,
                                       write_expr=PERM_EXPR % UserRate)


# BBB: We fake a class for these categories where the key can be
# overridden by sub-classes, hopefully this is all anyone customized.
class UserRating(object):
    """A dummy class which actually returns the result of calling the
    category factory, for BBB."""
    category = UserRatingCat
Exemplo n.º 16
0
from zope.schema.vocabulary import SimpleTerm, SimpleVocabulary
from contentratings.interfaces import _


def titled_vocab(items):
    terms = [SimpleTerm(k, title=v) for k, v in items]
    return SimpleVocabulary(terms)


five_star_vocab = titled_vocab(
    ((1, _(u'Poor')), (2, _(u'Fair')), (3, _(u'Good')), (4, _(u'Very Good')),
     (5, _(u'Excellent'))))

three_star_vocab = titled_vocab(
    ((1, _(u'Unacceptable')), (2, _(u'Acceptable')), (3, _(u'Excellent'))))
Exemplo n.º 17
0
from contentratings.category import RatingsCategoryFactory, BASE_KEY
from contentratings.interfaces import _
from contentratings.permissions import (
    EditorRate,
    ViewEditorialRating,
    UserRate,
    ViewUserRating,
    )
from contentratings.storage import EditorialRatingStorage, SINGLEKEY

# A Plone-y permission expression since these classes are just for BBB with
# Plone products
PERM_EXPR = ("python:getattr(getattr(context, 'portal_membership' ,None),"
                                 " 'checkPermission', lambda *x: True)('%s',"
                                                                    " context)")
EditorialRatingCat = RatingsCategoryFactory(_(u'Editor Rating'),
                                       read_expr=PERM_EXPR%ViewEditorialRating,
                                       write_expr=PERM_EXPR%EditorRate,
                                       storage=EditorialRatingStorage)
UserRatingCat = RatingsCategoryFactory(_(u'User Rating'),
                                       read_expr=PERM_EXPR%ViewUserRating,
                                       write_expr=PERM_EXPR%UserRate)

# BBB: We fake a class for these categories where the key can be
# overridden by sub-classes, hopefully this is all anyone customized.
class UserRating(object):
    """A dummy class which actually returns the result of calling the
    category factory, for BBB."""
    category = UserRatingCat
    key = BASE_KEY