How to use the kotti.workflow.get_workflow function in Kotti

To help you get started, we’ve selected a few Kotti examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Kotti / Kotti / kotti / alembic / versions / 57fecf5dbd62_initialize_workflow.py View on Github external
def upgrade():
    from kotti import DBSession
    from kotti import get_settings
    from kotti.resources import Document
    from kotti.workflow import get_workflow
    from kotti.workflow import reset_workflow

    is_default = get_settings()['kotti.use_workflow'] == 'kotti:workflow.zcml'
    if not is_default:
        return

    reset_workflow()
    for obj in DBSession.query(Document):
        workflow = get_workflow(obj)
        workflow.transition_to_state(obj, None, 'public')
github Kotti / Kotti / kotti / views / edit / actions.py View on Github external
wf.transition_to_state(child,
                                                       self.request,
                                                       to_state, )
                self.flash(_(u'Your changes have been saved.'), 'success')
            else:
                self.flash(_(u'No changes were made.'), 'info')
            return self.back('@@contents')

        if 'cancel' in self.request.POST:
            self.flash(_(u'No changes were made.'), 'info')
            return self.back('@@contents')

        ids = self._selected_children(add_context=False)
        items = transitions = []
        if ids is not None:
            wf = get_workflow(self.context)
            if wf is not None:
                items = DBSession.query(Node).filter(Node.id.in_(ids)).all()
                for item in items:
                        trans_info = wf.get_transitions(item, self.request)
                        for tran_info in trans_info:
                            if tran_info not in transitions:
                                transitions.append(tran_info)
        return {'items': items,
                'states': _states(self.context, self.request),
                'transitions': transitions, }
github Kotti / Kotti / kotti / views / edit / actions.py View on Github external
:result: List of ActionButtons.
    :rtype: list
    """
    buttons = []
    if get_paste_items(context, request):
        buttons.append(ActionButton("paste", title=_("Paste"), no_children=True))
    if context.children:
        buttons.append(ActionButton("copy", title=_("Copy")))
        buttons.append(ActionButton("cut", title=_("Cut")))
        buttons.append(
            ActionButton("rename_nodes", title=_("Rename"), css_class="btn btn-warning")
        )
        buttons.append(
            ActionButton("delete_nodes", title=_("Delete"), css_class="btn btn-danger")
        )
        if get_workflow(context) is not None:
            buttons.append(ActionButton("change_state", title=_("Change State")))
        buttons.append(ActionButton("up", title=_("Move up")))
        buttons.append(ActionButton("down", title=_("Move down")))
        buttons.append(ActionButton("show", title=_("Show")))
        buttons.append(ActionButton("hide", title=_("Hide")))
    return [button for button in buttons if button.permitted(context, request)]
github Kotti / Kotti / kotti / views / edit / actions.py View on Github external
:result: List of ActionButtons.
    :rtype: list
    """
    buttons = []
    if get_paste_items(context, request):
        buttons.append(ActionButton('paste', title=_(u'Paste'),
                                    no_children=True))
    if context.children:
        buttons.append(ActionButton('copy', title=_(u'Copy')))
        buttons.append(ActionButton('cut', title=_(u'Cut')))
        buttons.append(ActionButton('rename_nodes', title=_(u'Rename'),
                                    css_class=u'btn btn-warning'))
        buttons.append(ActionButton('delete_nodes', title=_(u'Delete'),
                                    css_class=u'btn btn-danger'))
        if get_workflow(context) is not None:
            buttons.append(ActionButton('change_state',
                                        title=_(u'Change State')))
        buttons.append(ActionButton('up', title=_(u'Move up')))
        buttons.append(ActionButton('down', title=_(u'Move down')))
        buttons.append(ActionButton('show', title=_(u'Show')))
        buttons.append(ActionButton('hide', title=_(u'Hide')))
    return [button for button in buttons if button.permitted(context, request)]
github Kotti / Kotti / kotti / views / edit / __init__.py View on Github external
def _state_info(context, request):
    wf = get_workflow(context)
    state_info = []
    if wf is not None:
        state_info = _translate_titles(wf.state_info(context, request))
    return state_info
github Kotti / Kotti / kotti / views / edit / actions.py View on Github external
""" Change state view. Renders either a view to handle workflow changes
        for multiple nodes or handle the selected workflow changes and get
        back to the referrer of the request.

        :result: Either a redirect response or a dictionary passed to the
                 template for rendering.
        :rtype: pyramid.httpexceptions.HTTPFound or dict
        """
        if "change_state" in self.request.POST:
            ids = self.request.POST.getall("children-to-change-state")
            to_state = self.request.POST.get("to-state", "no-change")
            include_children = self.request.POST.get("include-children")
            if to_state != "no-change":
                items = DBSession.query(Node).filter(Node.id.in_(ids)).all()
                for item in items:
                    wf = get_workflow(item)
                    if wf is not None:
                        wf.transition_to_state(item, self.request, to_state)
                    if include_children:
                        childs = self._all_children(item, permission="state_change")
                        for child in childs:
                            wf = get_workflow(child)
                            if wf is not None:
                                wf.transition_to_state(child, self.request, to_state)
                self.flash(_("Your changes have been saved."), "success")
            else:
                self.flash(_("No changes were made."), "info")
            return self.back("@@contents")

        if "cancel" in self.request.POST:
            self.flash(_("No changes were made."), "info")
            return self.back("@@contents")
github Kotti / Kotti / kotti / views / edit / actions.py View on Github external
def workflow(context, request):
    """
    Renders the drop down menu for workflow actions.

    :result: Dictionary passed to the template for rendering.
    :rtype: dict
    """
    wf = get_workflow(context)
    if wf is not None:
        state_info = _state_info(context, request)
        curr_state = [i for i in state_info if i['current']][0]
        trans_info = [trans for trans in wf.get_transitions(context, request)
                      if request.has_permission(trans['permission'], context)]

        return {
            'states': _states(context, request),
            'transitions': trans_info,
            'current_state': curr_state,
        }

    return {
        'current_state': None
    }
github Kotti / Kotti / kotti / views / edit / __init__.py View on Github external
def _state_info(context, request):
    wf = get_workflow(context)
    state_info = []
    if wf is not None:
        state_info = _translate_titles(wf.state_info(context, request))
    return state_info
github Kotti / Kotti / kotti / views / edit / actions.py View on Github external
def workflow_change(self):
        """
        Handle workflow change requests from workflow dropdown.

        :result: Redirect response to the referrer of the request.
        :rtype: pyramid.httpexceptions.HTTPFound
        """
        new_state = self.request.params['new_state']
        wf = get_workflow(self.context)
        wf.transition_to_state(self.context, self.request, new_state)
        self.flash(EditFormView.success_message, 'success')
        return self.back()