Ejemplo n.º 1
0
    def update(self, transition=None):
        self.adapters = {
            self.IWorkflowComment: WorkflowComment(),
            }

        wf = interfaces.IWorkflow(self.context) 
        
        if transition is not None:
            state_transition = wf.getTransitionById(transition)
            self.status = _(
                u"Confirmation required for workflow transition: '${title}'",
                mapping={'title': _(state_transition.title)})

        self.setupActions(transition)
        super(WorkflowActionViewlet, self).update()

        # after we transition we have different actions
        self.setupActions(transition)
        # only display the notes field to comment if there is an action
        # and a log table
        auditor = audit.getAuditor( self.context )
        if len(self.actions) == 0: 
            self.form_fields = self.form_fields.omit('note')
        elif auditor is None:
            self.form_fields = self.form_fields.omit('note')
        else:
            note_widget = TextAreaWidget
            note_widget.height = 1
            self.form_fields['note'].custom_widget = note_widget
                        
        self.setUpWidgets()
Ejemplo n.º 2
0
def get_wf_state(context, wf_state_id=None):
    """Get the human readable title for the context's workflow state
    """
    # !+ rename to: workflow_state_title
    wf = interfaces.IWorkflow(context)
    if wf_state_id is None:
        wf_state_id = interfaces.IWorkflowState(context).getState()
    return wf.workflow.states[wf_state_id].title
Ejemplo n.º 3
0
 def setupActions(self, transition):
     self.wf = interfaces.IWorkflowInfo(self.context)
     if transition is None:
         transitions = self.wf.getManualTransitionIds()
     else:
         transitions = (transition, )
     self.actions = bindTransitions(self, transitions, None,
                                    interfaces.IWorkflow(self.context))
Ejemplo n.º 4
0
 def setupActions(self):
     return
     wf = self.wf = interfaces.IWorkflowInfo(self.context, None)
     if wf is not None:
         transitions = self.wf.getManualTransitionIds()
         self.actions = tuple(
             bindTransitions(self, transitions, None,
                             interfaces.IWorkflow(self.context)))
Ejemplo n.º 5
0
    def __call__(self, headless=False, transition=None):
        method = self.request["REQUEST_METHOD"]
        if transition:
            wf = interfaces.IWorkflow(self.context)
            state_transition = wf.getTransitionById(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, interfaces.IWorkflow(self.context))
            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({})

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

            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
Ejemplo n.º 6
0
 def __call__(self, context):
     if IAlchemistContent.providedBy(context):
         ctx = context
     elif  IAlchemistContainer.providedBy(context):
         domain_model = removeSecurityProxy( context.domain_model )
         ctx = domain_model()
     wf = interfaces.IWorkflow(ctx)
     items=[]
     for state in wf.workflow.states.keys():
         items.append(SimpleTerm(wf.workflow.states[state].id,
                     wf.workflow.states[state].id,
                     _(wf.workflow.states[state].title)))
     return SimpleVocabulary(items)
Ejemplo n.º 7
0
    def update(self, transition=None):
        self.adapters = {
            self.IWorkflowComment: self.WorkflowComment(),
        }
        wf = interfaces.IWorkflow(self.context)

        if transition is not None:
            state_transition = wf.getTransitionById(transition)
            self.status = _(
                u"Confirmation required for workflow transition: '${title}'",
                mapping={"title": _(state_transition.title)})

        self.setupActions(transition)
        super(WorkflowActionViewlet, self).update()

        # after we transition we have different actions
        self.setupActions(transition)
        # only display the notes field to comment if there is an action
        # and a log table
        auditor = audit.getAuditor(self.context)
        if len(self.actions) == 0:
            self.form_fields = self.form_fields.omit("note", "date_active")
        elif auditor is None:
            self.form_fields = self.form_fields.omit("note", "date_active")
        else:
            # note widget
            note_widget = TextAreaWidget
            note_widget.height = 1
            self.form_fields["note"].custom_widget = note_widget
            # date_active widget
            self.form_fields["date_active"].custom_widget = TextDateTimeWidget
            # !+ for "past data entry" mode, the default "date_active" value
            # should be gotten from a "pseudo_current_date" service utility
        self.setUpWidgets()
        # update form status in case of any errors
        # !+ follow the "bungeni descriptor schema_invariants" way of doing
        # this, i.e. displaying widget-specific errors next to each widget
        if self.errors:
            if self.status is None:
                self.status = _("Errors")
            self.status = "%s: %s " % (
                self.status,
                " / ".join([
                    e.message  #or e.__class__.__name__ 
                    for e in self.errors
                ]))
Ejemplo n.º 8
0
 def update(self, transition=None):
     wf = interfaces.IWorkflow(self.context)
     if transition is not None:
         state_transition = wf.getTransitionById(transition)
         # !- workflow state title translations are in bungeni.core
         # use the right factory here to get translation
         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()
Ejemplo n.º 9
0
def get_wf_state(context):
    # return human readable workflow title
    wf = interfaces.IWorkflow(context)
    wf_state = interfaces.IWorkflowState(context).getState()
    return wf.workflow.states[wf_state].title