Esempio n. 1
0
    def update(self, transition_id=None):
        if IWorkspaceContainer.providedBy(self.context.__parent__):
            self._old_url = WorkspaceAbsoluteURLView(self.context,
                                                     self.request)()
        workflow = interfaces.IWorkflow(self.context)
        if transition_id:
            transition = workflow.get_transition(transition_id)
            title = translate(_(transition.title), context=self.request)
            self.status = translate(_(
                u"Confirmation required for workflow transition: '${title}'",
                mapping={"title": title}),
                                    context=self.request)
        self.setupActions(transition_id)

        if (ILegislativeContent.providedBy(self.context)
                and get_mask(self.context) == "manual"
                and not self.context.registry_number):
            self.form_fields = self.form_fields.omit("note", "date_active")
        else:
            self.form_fields = self.form_fields.omit("registry_number")

        if not self.actions:
            self.form_fields = self.form_fields.omit("note", "date_active")
        elif not IFeatureAudit.providedBy(self.context):
            self.form_fields = self.form_fields.omit("note", "date_active")
        # !+SUPERFLUOUS_ObejctModifiedEvent(mr, nov-2011) the following update()
        # is causing a ModifiedEvent to be fired, causing a modify change to be
        # logged (while this workflow change should be just that).
        super(WorkflowActionViewlet, self).update()
Esempio n. 2
0
def get_head_object_state_rpm(sub_context):
    """IRolePermissionMap(context) adapter factory.
    
    Lighweight and high-performance wrapper on get_object_state(context), 
    to *lookup* (note: no creation of any instance) the workflow.states.State 
    singleton instance for the sub context's head's status.
    
    Note that sub context is NOT workflowed.
    
    On lookup error, returns NONE_STATE_RPM, instead of what would be a 
    zope.component.ComponentLookupError.
    """
    try:
        head = sub_context.head
        return interfaces.IWorkflow(head).get_state(sub_context.status)
    except interfaces.InvalidStateError:
        from bungeni.models.interfaces import IChange
        if sub_context.status is None and IChange.providedBy(sub_context):
            # if status is None,then must have an "add" change action... ignore.
            assert sub_context.action == "add"
        else:
            # log it... !+bungeni.ui.utils.debug
            cls, exc, tb = sys.exc_info()
            log.error(""" ***get_head_object_state_rpm/%s:%s [%s] %s """ %
                      (type(sub_context).__name__, sub_context.pk,
                       cls.__name__, exc))
        return NONE_STATE_RPM
Esempio n. 3
0
def get_wf_state(context, wf_status=None):
    """Get the human readable title for the context's workflow state
    """
    # !+RENAME(mr, mar-2011) to get_workflow_state_title
    workflow = interfaces.IWorkflow(context)
    if wf_status is None:
        wf_status = interfaces.IStateController(context).get_status()
    return workflow.get_state(wf_status).title
Esempio n. 4
0
 def is_workflowed_and_draft(instance):
     """is item workflowed, and if so is it in a logical draft state?
     """
     if interfaces.IWorkflowed.providedBy(instance):
         wf = interfaces.IWorkflow(instance)
         return instance.status in wf.get_state_ids(tagged=["draft"],
                                                    restrict=False)
     return False
Esempio n. 5
0
def initializeWorkflow(object, event):
    """In response to object created events.
    event:zope.lifecycleevent.ObjectCreatedEvent
    """
    if interfaces.IWorkflow(object, None) is None:
        return
    
    workflow = interfaces.IWorkflowController(object, None)
    if workflow is not None:
        workflow.fireAutomatic()
Esempio n. 6
0
def fireAutomaticTransitions(object, event):
    """Fire automatic transitions for a new state.
    event:bungeni.core.workflow.interfaces.IWorkflowTransitionEvent
    """
    if interfaces.IWorkflow(object, None) is None:
        return
    
    workflow = interfaces.IWorkflowController(object, None)
    if workflow is not None:
        workflow.fireAutomatic()
Esempio n. 7
0
def get_wf_state(context, wf_status=None):
    """Get the human readable title for the context's workflow state
    """
    workflow = interfaces.IWorkflow(context, None)
    if workflow is None:
        log.warn("No workflow exists for %s", context)
        return ""  # !+ !!
    if wf_status is None:
        # retrieve and use current status
        wf_status = interfaces.IStateController(context).get_status()
    # ok, pick off the current state's title
    return workflow.get_state(wf_status).title
Esempio n. 8
0
 def __call__(self, context):
     if IAlchemistContent.providedBy(context):
         ctx = context
     elif  IAlchemistContainer.providedBy(context):
         domain_model = removeSecurityProxy(context.domain_model)
         ctx = domain_model()
     workflow = interfaces.IWorkflow(ctx)
     items = []
     for status in workflow.states.keys():
         items.append(SimpleTerm(status, status, 
             _(workflow.get_state(status).title)))
     return SimpleVocabulary(items)
Esempio n. 9
0
def get_object_state(context):
    """Utility to look up the workflow.states.State singleton instance that 
    corresponds to the context's urrent status.
    
    Implemented as the IWorkflow adaptor for the context--but as may need to 
    be called numerous times per request, note that it is a lightweight and 
    performance-aware adapter -- there is no creation of any adapter instance, 
    just lookup of the object's Workflow instance off which to retrieve 
    existing State instances.
    
    Raises interfaces.InvalidStateError.
    """
    return interfaces.IWorkflow(context).get_state(context.status)
Esempio n. 10
0
 def update(self, transition=None):
     # !+RENAME(mr, apr-2011) should be transition_id
     workflow = interfaces.IWorkflow(self.context)
     if transition is not None:
         state_transition = workflow.get_transition(transition)
         state_title = translate(_bc(state_transition.title),
                             context=self.request)
         self.status = translate(_(
             u"Confirmation required for workflow transition: '${title}'",
             mapping={"title": state_title}), context = self.request)
     self.setupActions(transition)
     if not self.actions: 
         self.form_fields = self.form_fields.omit("note", "date_active")
     elif not IAuditable.providedBy(self.context):
         self.form_fields = self.form_fields.omit("note", "date_active")
     super(WorkflowActionViewlet, self).update()
Esempio n. 11
0
    def __call__(self, transition_id=None, headless=False):
        # parameters coming in via URL querystring or post vars !
        method = self.request["REQUEST_METHOD"]
        # !+ALWAYS_POST(mr, sep-2011) requests coming from link clicks (GETs)
        # from the bungeni Web UI seem to always be intercepted and switched
        # into POSTs.
        workflow = interfaces.IWorkflow(self.context)

        require_confirmation = True
        if transition_id is not None:
            self.update(transition_id)
            require_confirmation = workflow.get_transition(
                transition_id).require_confirmation
        else:
            self.update()

        if (ILegislativeContent.providedBy(self.context)
                and get_mask(self.context) == "manual"
                and not self.context.registry_number):
            require_confirmation = True

        if (not require_confirmation and method == "POST"):
            actions = bindTransitions(self.action_viewlet, (transition_id, ),
                                      workflow)
            assert len(actions) == 1
            # execute action
            # !+ should pass self.request.form as data? e.g. value is:
            # {u"next_url": u"...", u"transition": u"submit_response"}
            result = actions[0].success({})
            # !+UNUSED(mr, jun-2011) this result is never used!

        if headless:
            actions = get_actions("context_workflow", self.context,
                                  self.request)
            state_title = workflow.get_state(self.context.status).title
            result = self.ajax_template(actions=actions,
                                        state_title=state_title)
            if require_confirmation:
                self.request.response.setStatus(403)
            else:
                self.request.response.setStatus(200)
                self.request.response.setResult(result)
                self.request.response.setHeader("Content-Type", "text/xml")
            return result

        template = self.template()
        return template
Esempio n. 12
0
    def __call__(self, headless=False, transition=None):
        # !+RENAME(mr, apr-2011) should be transition_id
        method = self.request["REQUEST_METHOD"]
        workflow = interfaces.IWorkflow(self.context)

        # !+REWITE(mr, jun-2011) the following needs to be rewritten!
        if transition:
            state_transition = workflow.get_transition(transition)
            require_confirmation = getattr(state_transition,
                                           "require_confirmation", False)
            self.update(transition)
        else:
            self.update()

        if transition and require_confirmation is False and method == "POST":
            actions = bindTransitions(self.action_viewlet, (transition, ),
                                      None, workflow)
            assert len(actions) == 1
            # execute action
            # !+ should pass self.request.form as data? e.g. value is:
            # {u"next_url": u"...", u"transition": u"submit_response"}
            result = actions[0].success({})
            # !+REWITE(mr, jun-2011) this result is never used!

        if headless is True:
            actions = get_actions("context_workflow", self.context,
                                  self.request)
            state_title = workflow.get_state(self.context.status).title
            result = self.ajax_template(actions=actions,
                                        state_title=state_title)

            # !+REWITE(mr, jun-2011) require_confirmation only defined when
            # transition is True!
            if require_confirmation is True:
                self.request.response.setStatus(403)
            else:
                self.request.response.setStatus(200)
                self.request.response.setResult(result)
                self.request.response.setHeader("Content-Type", "text/xml")

            return result

        template = self.template()
        return template
Esempio n. 13
0
 def update(self, transition_id=None):
     workflow = interfaces.IWorkflow(self.context)
     if transition_id:
         transition = workflow.get_transition(transition_id)
         title = translate(_(transition.title), context=self.request)
         self.status = translate(
             _(u"Confirmation required for workflow transition: '${title}'",
                 mapping={"title": title}
             ), 
             context=self.request)
     self.setupActions(transition_id)
     
     if get_mask(self.context) == 'manual' and not self.context.registry_number:
         self.form_fields = self.form_fields.omit("note", "date_active")
     else:
         self.form_fields = self.form_fields.omit("registry_number")
     if not self.actions: 
         self.form_fields = self.form_fields.omit("note", "date_active")
     elif not IAuditable.providedBy(self.context):
         self.form_fields = self.form_fields.omit("note", "date_active")
     super(WorkflowActionViewlet, self).update()
Esempio n. 14
0
 def workflow(self):
     """ () -> bungeni.core.workflow.states.Workflow """
     return interfaces.IWorkflow(self.context)