Example #1
0
class RatingPortlet(object):

    def update(self):
        if not self.isAvailable():
            return
        try:
            context = self.manager.view.maincontext
        except AttributeError:
            context = self.context
        self.contextURL = absoluteURL(context, self.request)
        if self.allowRate:
            self.form = RateForm(context, self.request)
            self.form.update()

    @Lazy
    def average(self):
        context = self.manager.view.maincontext
        averageRating = IAverageRating(context, None)
        if averageRating is None:
            return None
        return averageRating.average

    @Lazy
    def allowRate(self):
        context = self.manager.view.maincontext
        return checkPermission('zojax.rating.Rate', context)

    def isAvailable(self):
        if self.manager.view is None:
            return False

        try:
            context = self.manager.view.maincontext
        except AttributeError:
            context = self.context

        if not IRatable.providedBy(context):
            return False

        return self.average is not None or self.allowRate

    @Lazy
    def averageAsString(self):
        return "%i_%s" % (int(self.average),
                          self.average % 1 > 0.4 and '5' or '0')
Example #2
0
 def update(self):
     if not self.isAvailable():
         return
     try:
         context = self.manager.view.maincontext
     except AttributeError:
         context = self.context
     self.contextURL = absoluteURL(context, self.request)
     if self.allowRate:
         self.form = RateForm(context, self.request)
         self.form.update()