def lock_proposals(poll, request): """ Set proposals to voting. """ count = 0 for proposal in poll.get_proposal_objects(): if 'voting' in [ x['name'] for x in proposal.get_available_workflow_states(request) ]: proposal.set_workflow_state(request, 'voting') count += 1 if count: fm = FlashMessages(request) localizer = get_localizer(request) prop_form = localizer.pluralize(_(u"proposal"), _(u"proposals"), count) ts = _ #So i18n tools don't pick it up prop_form = localizer.translate(ts(prop_form)) msg = _( u'poll_proposals_locked_notice', default=u"Setting ${count} ${prop_form} as 'locked for vote'. " u"They can no longer be edited or retracted by normal users. " u"All proposals participating in an ongoing poll should be locked.", mapping={ 'count': count, 'prop_form': prop_form }) fm.add(msg)
def upcoming_poll_callback(poll, info): """ Workflow callback when a poll is set in the upcoming state. This method sets all proposals in the locked for vote-state. """ request = get_current_request() lock_proposals(poll, request) fm = FlashMessages(request) msg = _('poll_upcoming_state_notice', default=u"Setting poll in upcoming state. It's now visible for meeting participants.") fm.add(msg)
def adjust_proposal_states(self, uid_states, request=None): assert isinstance(uid_states, dict) if request is None: request = get_current_request() locale = get_localizer(request) fm = FlashMessages(request) for (uid, state) in uid_states.items(): if uid not in self.proposal_uids: raise ValueError( "The poll plugins close() method returned a uid that doesn't exist in this poll." ) proposal = self.get_proposal_by_uid(uid) #Adjust state? prop_wf_state = proposal.get_workflow_state() #Message strings can't contain other message strings, so we'll translate the state first translated_state = locale.translate(_(state.title())) if prop_wf_state == state: msg = _( 'change_prop_state_already_that_state_error', default=u"Proposal '${name}' already in state ${state}", mapping={ 'name': proposal.__name__, 'state': translated_state }) fm.add(msg) else: try: proposal.set_workflow_state(request, state) msg = _('prop_state_changed_notice', default=u"Proposal '${name}' set as ${state}", mapping={ 'name': proposal.__name__, 'state': translated_state }) fm.add(msg) except WorkflowError: msg = _( 'prop_state_change_error', default= u"Proposal with id '${name}' couldn't be set as ${state}. You should do this manually.", mapping={ 'name': proposal.__name__, 'state': translated_state }) fm.add(msg, type='error') msg = _( 'poll_closed_info', default= u"Poll closed. Proposals might have been adjusted as approved or denied depending on outcome of the poll." ) fm.add(msg)
def upcoming_poll_callback(poll, info): """ Workflow callback when a poll is set in the upcoming state. This method sets all proposals in the locked for vote-state. """ request = get_current_request() lock_proposals(poll, request) fm = FlashMessages(request) msg = _( 'poll_upcoming_state_notice', default= u"Setting poll in upcoming state. It's now visible for meeting participants." ) fm.add(msg)
def lock_proposals(poll, request): """ Set proposals to voting. """ count = 0 for proposal in poll.get_proposal_objects(): if 'voting' in [x['name'] for x in proposal.get_available_workflow_states(request)]: proposal.set_workflow_state(request, 'voting') count += 1 if count: fm = FlashMessages(request) localizer = get_localizer(request) prop_form = localizer.pluralize(_(u"proposal"), _(u"proposals"), count) ts = _ #So i18n tools don't pick it up prop_form = localizer.translate(ts(prop_form)) msg = _(u'poll_proposals_locked_notice', default=u"Setting ${count} ${prop_form} as 'locked for vote'. " u"They can no longer be edited or retracted by normal users. " u"All proposals participating in an ongoing poll should be locked.", mapping={'count':count, 'prop_form': prop_form}) fm.add(msg)
def adjust_proposal_states(self, uid_states, request = None): assert isinstance(uid_states, dict) if request is None: request = get_current_request() locale = get_localizer(request) fm = FlashMessages(request) for (uid, state) in uid_states.items(): if uid not in self.proposal_uids: raise ValueError("The poll plugins close() method returned a uid that doesn't exist in this poll.") proposal = self.get_proposal_by_uid(uid) #Adjust state? prop_wf_state = proposal.get_workflow_state() #Message strings can't contain other message strings, so we'll translate the state first translated_state = locale.translate(_(state.title())) if prop_wf_state == state: msg = _('change_prop_state_already_that_state_error', default=u"Proposal '${name}' already in state ${state}", mapping={'name':proposal.__name__, 'state':translated_state}) fm.add(msg) else: try: proposal.set_workflow_state(request, state) msg = _('prop_state_changed_notice', default=u"Proposal '${name}' set as ${state}", mapping={'name':proposal.__name__, 'state':translated_state}) fm.add(msg) except WorkflowError: msg = _('prop_state_change_error', default=u"Proposal with id '${name}' couldn't be set as ${state}. You should do this manually.", mapping={'name':proposal.__name__, 'state':translated_state}) fm.add(msg, type='error') msg = _('poll_closed_info', default=u"Poll closed. Proposals might have been adjusted as approved or denied depending on outcome of the poll.") fm.add(msg)