def adjust_proposal_states(self, uid_states, request = None): assert isinstance(uid_states, dict) if request is None: request = get_current_request() changed = [] change_error = [] 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() if prop_wf_state != state: try: proposal.set_workflow_state(request, state) changed.append(proposal) except WorkflowError: change_error.append(proposal) fm = get_flash_messages(request) msg = _('poll_closed_info', default = "Poll has now closed. ${num} proposal(s) are now set in another state due to the outcome of the poll.", mapping = {'num': len(changed)}) fm.add(msg) if change_error: msg = _('poll_closed_proposal_wf_change_error', default = "Couldn't adjust the state of the following proposal(s): '${props}'. " "You may wish to review them manually.", mapping = {'props': "', '".join(prop.aid for prop in change_error)}) fm.add(msg, type = 'danger')
def set_delegate_view(context, request, name = None): name = request.GET.get('name', name) if name is None: raise HTTPForbidden("Need to specify a request with the GET variable name or simply a name parameter.") fm = get_flash_messages(request) if name: if name not in context: raise HTTPNotFound("No content with that name") context.delegate_view = name title = getattr(context[name], 'title', context[name].__name__) fm.add(_("View delegated to '${title}'", mapping = {'title': title})) else: context.delegate_view = None fm.add(_("Normal view restored")) return HTTPFound(location = request.resource_url(context))
def set_view(context, request, name = None): name = request.GET.get('name', name) if name is None: raise ValueError("Need to specify a request with the GET variable name or simply a name parameter.") if get_view(context, request, view_name = name) is None: raise HTTPForbidden(u"There's no view registered for this content type with that name. " u"Perhaps you forgot to register the view for this context?") context.default_view = name if name != 'view': title = get_content_views(request.registry)[context.type_name][name] else: title = _("Default view") fm = get_flash_messages(request) fm.add(_("View set to '${title}'", mapping = {'title': title})) #Remove settings. Should this be a subscriber instead? It's a bit destructive too, especially if clearing this isn't needed if hasattr(context, '__view_settings__'): delattr(context, '__view_settings__') return HTTPFound(location = request.resource_url(context))
def flash_messages(self): return get_flash_messages(self.request)