def processForm(self):
        form = self.request.form
        messages = IStatusMessage(self.request)
        if form:
            manager = IUsefulnessSettingsManager(self.context)
            if 'disable_rating' in form:
                manager.disableRating()
                messages.addStatusMessage(
                    _(u'Rating was disabled for this object'))
            elif 'disable_rating_children' in form:
                manager.disableRating(children=True)
                messages.addStatusMessage(
                    _(u'Rating was disabled for this object and its children'))
            elif 'enable_rating' in form:
                manager.enableRating()
                messages.addStatusMessage(
                    _(u'Rating was enabled for this object'))
            elif 'enable_rating_children' in form:
                manager.enableRating(children=True)
                messages.addStatusMessage(
                    _(u'Rating was enabled for this object and its children'))

            self.request.RESPONSE.redirect(self.request.URL)
        else:
            # no form submitted, do nothing
            pass
Esempio n. 2
0
class WasThisUsefulSettingsEditForm(controlpanel.RegistryEditForm):

    schema = IWasThisUsefulSettings
    label = _(u"Was This Useful settings")
    description = _(u"""""")

    def updateFields(self):
        super(WasThisUsefulSettingsEditForm, self).updateFields()

    def updateWidgets(self):
        super(WasThisUsefulSettingsEditForm, self).updateWidgets()
class IWasThisUsefulSettings(Interface):
    """Global settings for "Was this useful".
    This describes records stored in the
    configuration registry and obtainable via plone.registry.
    """

    enabled_types = schema.Tuple(
        title=_(u'label_enabled_types', default=u'Enabled types'),
        description=_(u"help_enabled_types",
                      default=u"For which content types shall "
                      u"we enable rating?"),
        required=False,
        default=('Document', ),
        value_type=schema.Choice(
            vocabulary="plone.app.vocabularies.UserFriendlyTypes"),
    )
class usefulnessRatingCommentSubstitution(BaseSubstitution):
    category = PloneStringInterpMessageFactory(u'All Content')
    description = _(u'label_comment', default=u'Comment')

    def safe_call(self):
        manager = UsefulnessManager(self.context)
        last_vote_comment = manager.getVotes()[-1].get(KEY_COMMENT)
        return last_vote_comment
 def _addVote(self, vote):
     manager = IUsefulnessManager(self.context)
     votes = manager.getVotes()
     votes.append(vote)
     manager.setVotes(votes)
     event = UsefulnessEvent(self.context)
     zope.event.notify(event)
     self.messages.addStatusMessage(
         _(u'message_thank_you', default=u'Thank you for voting!'))
 def _addVote(self, vote):
     manager = IUsefulnessManager(self.context)
     votes = manager.getVotes()
     votes.append(vote)
     manager.setVotes(votes)
     event = UsefulnessEvent(self.context)
     zope.event.notify(event)
     self.messages.addStatusMessage(_(u'message_thank_you',
                                      default=u'Thank you for voting!'))
class usefulnessRatingValueSubstitution(BaseSubstitution):
    category = PloneStringInterpMessageFactory(u'All Content')
    description = _(u'label_value', default=u'Rating')

    def safe_call(self):
        manager = UsefulnessManager(self.context)
        last_vote_value = manager.getVotes()[-1].get(KEY_USEFUL)
        if last_vote_value:
            value = 'Yes'
        else:
            value = 'No'
        return value
    def processForm(self):
        form = self.request.form
        messages = IStatusMessage(self.request)
        if form:
            manager = IUsefulnessSettingsManager(self.context)
            if "disable_rating" in form:
                manager.disableRating()
                messages.addStatusMessage(_(u"Rating was disabled for this object"))
            elif "disable_rating_children" in form:
                manager.disableRating(children=True)
                messages.addStatusMessage(_(u"Rating was disabled for this object and its children"))
            elif "enable_rating" in form:
                manager.enableRating()
                messages.addStatusMessage(_(u"Rating was enabled for this object"))
            elif "enable_rating_children" in form:
                manager.enableRating(children=True)
                messages.addStatusMessage(_(u"Rating was enabled for this object and its children"))

            self.request.RESPONSE.redirect(self.request.URL)
        else:
            # no form submitted, do nothing
            pass