Example #1
0
    def __call__(self, context):

        context = getattr(context, 'context', context)
        portal_catalog = getToolByName(context, 'portal_catalog')

        # Basic options
        voc = [
            SimpleTerm('hidden',
                       title=_(u'label_portlet_configuration_hidden',
                               default=u"Hidden")),
            SimpleTerm('newest',
                       title=_(u'label_portlet_configuration_newest',
                               default=u"Newest")),
            SimpleTerm('branch',
                       title=_(u'label_portlet_configuration_branch',
                               default=u"Branch")),
            SimpleTerm('subbranches',
                       title=_(u'label_portlet_configuration_subbranches',
                               default="Subbranches"))
        ]

        # Adding existing polls
        brains = portal_catalog.unrestrictedSearchResults(
            meta_type='PlonePopoll', allowedRolesAndUsers=['Anonymous'])
        for brain in brains:  # Brains
            poll = brain.getObject()
            path = '/'.join(poll.getPhysicalPath())
            title = "%s (%s)" % (safe_unicode(brain.Title), safe_unicode(path))
            voc.append(SimpleTerm(poll.UID(), title=title))
        return SimpleVocabulary(voc)
Example #2
0
    def __call__(self, context):

        context = getattr(context, 'context', context)
        portal_catalog = getToolByName(context, 'portal_catalog')

        # Basic options
        voc = [
            SimpleTerm('hidden',
                       title=_(u'label_portlet_configuration_hidden',
                               default=u"Hidden")),
            SimpleTerm('newest',
                       title=_(u'label_portlet_configuration_newest',
                               default=u"Newest")),
            SimpleTerm('branch',
                       title=_(u'label_portlet_configuration_branch',
                               default=u"Branch")),
            SimpleTerm('subbranches',
                       title=_(u'label_portlet_configuration_subbranches',
                               default="Subbranches"))
        ]

        # Adding existing polls
        brains = portal_catalog(object_provides=IPlonePopoll.__identifier__)
        for brain in brains:  # Brains
            poll = brain.getObject()
            path = '/'.join(poll.getPhysicalPath())
            title = "%s (%s)" % (safe_unicode(brain.Title), safe_unicode(path))
            voc.append(SimpleTerm(poll.UID(), title=title))
        return SimpleVocabulary(voc)
Example #3
0
class AddForm(base.AddForm):
    """Add form for our portlet"""

    form_fields = form.Fields(IPopollPortlet)

    label = _(u"add_portlet")
    description = _(u"desc_portlet")

    def create(self, data):
        return Assignment(selection_mode=data.get('selection_mode', 'hidden'),
                          number_of_polls=data.get('number_of_polls', 5))
Example #4
0
class IPopollPortlet(IPortletDataProvider):
    """Portlet configuration data model"""

    selection_mode = schema.Choice(
        title=_(u'label_plonepopoll_portlet_configuration'),
        description=_(u'help_plonepopoll_portlet_configuration'),
        vocabulary="popoll.portlet.pollselection")

    number_of_polls = schema.Int(
        title=_(u'label_plonepopoll_portlet_configuration_number_of_polls'),
        description=_(
            u'help_plonepopoll_portlet_configuration_number_of_polls'),
        required=True,
        default=5)
    def __call__(self, context):

        context = getattr(context, 'context', context)
        portal_catalog = getToolByName(context, 'portal_catalog')

        # Basic options
        voc  = [
            SimpleTerm('hidden', title=_(u'label_portlet_configuration_hidden', default=u"Hidden")),
            SimpleTerm('newest', title=_(u'label_portlet_configuration_newest', default=u"Newest")),
            SimpleTerm('branch', title=_(u'label_portlet_configuration_branch', default=u"Branch")),
            SimpleTerm('subbranches', title=_(u'label_portlet_configuration_subbranches', default="Subbranches"))
            ]

        # Adding existing polls
        brains = portal_catalog(object_provides=IPlonePopoll.__identifier__)
        for brain in brains: # Brains
            poll = brain.getObject()
            path = '/'.join(poll.getPhysicalPath())
            title = "%s (%s)" % (safe_unicode(brain.Title), safe_unicode(path))
            voc.append(SimpleTerm(poll.UID(), title=title))
        return SimpleVocabulary(voc)
    def vote(self, choices=[], clear=False, redirect=True, redirect_url=None):
        """
        vote(self, choices = [], clear = False )
        - calls the backend to register votes
        - Include all the necessary code to pseudo-guarantee the unicity of the vote.
        """
        if not self.isEnabled():
            raise RuntimeError, "This poll is not active."
        if self.hasVoted():
            self.removeUserVote()

        request = self.REQUEST
        response = request.RESPONSE
        # choices contains the user choice (if 1 result max OR a table of results if authorized result > 1)
        if type(choices) is str:
            checkedCount = 1
        else:
            checkedCount = len(choices)
        max_votes = int(self.getNumber_of_choices())
        if clear:
            self.clearResults()
            msgstr = "Poll results have been cleared."
            msgid = "results_cleared"

        else:
            if checkedCount > max_votes and self._check_multi:
                msgstr = "You have made ${checked} choices. The maximum authorized is ${max}."
                msgid = 'message_check_count'

            else:
                portal_popoll = getToolByName(self, 'portal_popoll')
                # Ensure unicity of the vote
                unicity = portal_popoll.getVoteUnicity(self.getVoteId(), create=1)
                if type(choices) is str:
                    if int(choices) < 0:
                        raise ValueError, "Invalid choice"
                    portal_popoll.getBackend().vote(self.getVoteId(), int(choices), unicity)
                else:
                    for choice in choices:
                        # Check that choice is valid
                        if int(choice) >= len(self.choices) or int(choice) < 0:
                            raise ValueError, "Invalid choice"
                        # Call the method in the backend to store the vote
                        portal_popoll.getBackend().vote(self.getVoteId(), int(choice), unicity)
                msgstr = "Vote has been saved."
                msgid = "vote_saved"

        message = _(unicode(msgid), default=unicode(msgstr), mapping={'checked': checkedCount, 'max': max_votes})
        plone_utils = getToolByName(self, 'plone_utils')
        plone_utils.addPortalMessage(message)
        if redirect:
            url = redirect_url or self.absolute_url()
            return response.redirect(url)
    def vote(self, choices=[], clear=False, redirect=True, redirect_url=None):
        """
        vote(self, choices = [], clear = False )
        - calls the backend to register votes
        - Include all the necessary code to pseudo-guarantee the unicity of the vote.
        """
        if not self.isEnabled():
            raise RuntimeError, "This poll is not active."
        if self.hasVoted():
            self.removeUserVote()

        request = self.REQUEST
        response = request.RESPONSE

        checkedCount = len(choices)
        max_votes = int(self.getNumber_of_choices())
        if clear:
            self.clearResults()
            msgstr = "Poll results have been cleared."
            msgid = "results_cleared"

        else:
            if checkedCount > max_votes and self._check_multi:
                msgstr = "You have made ${checked} choices. The maximum authorized is ${max}."
                msgid = 'message_check_count'

            else:
                portal_popoll = getToolByName(self, 'portal_popoll')
                # Ensure unicity of the vote
                unicity = portal_popoll.getVoteUnicity(self.getVoteId(),
                                                       create=1)
                for choice in choices:
                    # Check that choice is valid
                    if int(choice) >= len(self.choices) or int(choice) < 0:
                        raise ValueError, "Invalid choice"

                    # Call the method in the backend to store the vote
                    portal_popoll.getBackend().vote(self.getVoteId(),
                                                    int(choice), unicity)
                msgstr = "Vote has been saved."
                msgid = "vote_saved"

        message = _(unicode(msgid),
                    default=unicode(msgstr),
                    mapping={
                        'checked': checkedCount,
                        'max': max_votes
                    })
        plone_utils = getToolByName(self, 'plone_utils')
        plone_utils.addPortalMessage(message)
        if redirect:
            url = redirect_url or self.absolute_url()
            return response.redirect(url)
Example #8
0
    def __call__(self, context):

        context = getattr(context, 'context', context)
        portal_catalog = getToolByName(context, 'portal_catalog')

        # Basic options
        voc  = [
            SimpleTerm('hidden', title=_(u'label_portlet_configuration_hidden', default=u"Hidden")),
            SimpleTerm('newest', title=_(u'label_portlet_configuration_newest', default=u"Newest")),
            SimpleTerm('branch', title=_(u'label_portlet_configuration_branch', default=u"Branch")),
            SimpleTerm('subbranches', title=_(u'label_portlet_configuration_subbranches', default="Subbranches"))
            ]

        # Adding existing polls
        brains = portal_catalog.unrestrictedSearchResults(meta_type='PlonePopoll',
            allowedRolesAndUsers=['Anonymous'])
        for brain in brains: # Brains
            poll = brain.getObject()
            path = '/'.join(poll.getPhysicalPath())
            title = "%s (%s)" % (safe_unicode(brain.Title), safe_unicode(path))
            voc.append(SimpleTerm(poll.UID(), title=title))
        return SimpleVocabulary(voc)
Example #9
0
class EditForm(base.EditForm):
    """Edit form for our portlet"""

    form_fields = form.Fields(IPopollPortlet)
    label = _(u"edit_portlet")
    description = _(u"desc_portlet")
Example #10
0
 def title(self):
     return _(u'heading_portlet_polls')
Example #11
0
 def title(self):
     return _(u'heading_portlet_polls')