def test_view(root, workflow): from kotti.workflow import get_workflow from kotti_calendar.resources import Calendar from kotti_calendar.resources import Event from kotti_calendar.widgets import upcoming_events now = datetime.now() result = upcoming_events(root, DummyRequest()) assert len(result['events']) == 0 root['calendar'] = Calendar() root['calendar']['event1'] = event1 = Event( title=u'Event 1', start=now - timedelta(1), end=now + timedelta(2)) root['calendar']['event2'] = event2 = Event( title=u'Event 2', start=now + timedelta(1), end=now + timedelta(2)) wf = get_workflow(event1) wf.transition_to_state(event1, None, u'public') wf = get_workflow(event2) wf.transition_to_state(event2, None, u'public') result = upcoming_events(root, DummyRequest()) events = result['events'] assert len(events) == 2 assert events[0].title == u'Event 1' assert events[0].start == now - timedelta(1) assert events[1].title == u'Event 2' assert events[1].start == now + timedelta(1)
def test_view(root, workflow): from kotti.workflow import get_workflow from kotti_calendar.resources import Calendar from kotti_calendar.resources import Event from kotti_calendar.widgets import upcoming_events now = datetime.now() result = upcoming_events(root, DummyRequest()) assert len(result['events']) == 0 root['calendar'] = Calendar() root['calendar']['event1'] = event1 = Event(title=u'Event 1', start=now - timedelta(1), end=now + timedelta(2)) root['calendar']['event2'] = event2 = Event(title=u'Event 2', start=now + timedelta(1), end=now + timedelta(2)) wf = get_workflow(event1) wf.transition_to_state(event1, None, u'public') wf = get_workflow(event2) wf.transition_to_state(event2, None, u'public') result = upcoming_events(root, DummyRequest()) events = result['events'] assert len(events) == 2 assert events[0].title == u'Event 1' assert events[0].start == now - timedelta(1) assert events[1].title == u'Event 2' assert events[1].start == now + timedelta(1)
def change_state(self): """ 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', u'no-change') include_children = self.request.POST.get('include-children', None) if to_state != u'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.request.session.flash(_(u'Your changes have been saved.'), 'success') else: self.request.session.flash(_(u'No changes made.'), 'info') return self.back('@@contents') if 'cancel' in self.request.POST: self.request.session.flash(_(u'No changes 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, }
def change_state(self): """ 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', u'no-change') include_children = self.request.POST.get('include-children', None) if to_state != u'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.request.session.flash( _(u'Your changes have been saved.'), 'success') else: self.request.session.flash(_(u'No changes made.'), 'info') return self.back('@@contents') if 'cancel' in self.request.POST: self.request.session.flash(_(u'No changes 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, }
def change_state(self): """ 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") 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, }
def test_add_wf_interface_to_content(self, workflow): from zope import interface from kotti.resources import Content from kotti.workflow import get_workflow from kotti.interfaces import IDefaultWorkflow content = Content() assert get_workflow(content) is None assert content.state is None interface.directlyProvides(content, IDefaultWorkflow) wf = get_workflow(content) wf.transition_to_state(content, None, "public") assert content.state == "public"
def test_add_wf_interface_to_content(self, workflow): from zope import interface from kotti.resources import Content from kotti.workflow import get_workflow from kotti.interfaces import IDefaultWorkflow content = Content() assert get_workflow(content) is None assert content.state is None interface.directlyProvides(content, IDefaultWorkflow) wf = get_workflow(content) wf.transition_to_state(content, None, u'public') assert content.state == u'public'
def populate(): """ Create the root node (:class:`~kotti.resources.Document`) and the 'about' subnode in the nodes tree if there are no nodes yet. """ lrm = LocalizerRequestMixin() lrm.registry = get_current_registry() # noinspection PyPropertyAccess lrm.locale_name = get_settings()["pyramid.default_locale_name"] localizer = lrm.localizer if DBSession.query(Node.id).count() == 0: localized_root_attrs = { k: localizer.translate(v) for k, v in _ROOT_ATTRS.items() } root = Document(**localized_root_attrs) root.__acl__ = SITE_ACL DBSession.add(root) localized_about_attrs = { k: localizer.translate(v) for k, v in _ABOUT_ATTRS.items() } root["about"] = Document(**localized_about_attrs) wf = get_workflow(root) if wf is not None: DBSession.flush() # Initializes workflow wf.transition_to_state(root, None, "public") populate_users()
def populate(): """ Create the root node (:class:`~kotti.resources.Document`) and the 'about' subnode in the nodes tree if there are no nodes yet. """ lrm = LocalizerRequestMixin() lrm.registry = get_current_registry() lrm.locale_name = get_settings()['pyramid.default_locale_name'] localizer = lrm.localizer if DBSession.query(Node).count() == 0: localized_root_attrs = dict( [(k, localizer.translate(v)) for k, v in _ROOT_ATTRS.iteritems()]) root = Document(**localized_root_attrs) root.__acl__ = SITE_ACL DBSession.add(root) localized_about_attrs = dict( [(k, localizer.translate(v)) for k, v in _ABOUT_ATTRS.iteritems()]) root['about'] = Document(**localized_about_attrs) wf = get_workflow(root) if wf is not None: DBSession.flush() # Initializes workflow wf.transition_to_state(root, None, u'public') populate_users()
def test_workflow_transition(self, root, workflow, events): from kotti.workflow import get_workflow content = self.make_document(root) wf = get_workflow(content) wf.transition_to_state(content, None, "public") assert content.state == "public"
def create_fruit_category(self, request): data = ast.literal_eval(request.body) # Assume only one fruit_categories folder. fruit_categories_folder = \ DBSession.query(FruitCategoriesFolder).first() name = str(uuid.uuid4()) fruit_category = FruitCategory(name=name, title=data['title'], parent=fruit_categories_folder) fruit_category.__acl__ = SITE_ACL session = DBSession() session.add(fruit_category) workflow = get_workflow(fruit_category) if workflow: session.flush() workflow.transition_to_state(fruit_category, None, u'public') else: print '################ NO WORKFLOW for ', fruit_category.title session.flush() transaction.commit() fruit_category = \ DBSession.query(FruitCategory).filter_by(name=name).first() return {u'id': fruit_category.id, u'title': fruit_category.title}
def contents_buttons(context, request): """ Build the action buttons for the contents view based on the current state and the persmissions of the user. :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)]
def create_fruit(self, request): data = ast.literal_eval(request.body) fruit_category = \ DBSession.query(FruitCategory).filter_by( id=data['fruit_category']).first() name = str(uuid.uuid4()) fruit = Fruit(parent=fruit_category) fruit.__acl__ = SITE_ACL session = DBSession() session.add(fruit) workflow = get_workflow(fruit) if workflow: session.flush() workflow.transition_to_state(fruit, None, u'public') else: print '################ NO WORKFLOW for ', fruit.title session.flush() transaction.commit() fruit = DBSession.query(Fruit).filter_by(name=name).first() return {u'id': fruit.id, u'title': fruit.title, u'fruit_category': fruit.__parent__.id}
def test_workflow_transition(self, root, workflow, events): from kotti.workflow import get_workflow content = self.make_document(root) wf = get_workflow(content) wf.transition_to_state(content, None, u"public") assert content.state == u"public"
def contents_buttons(context, request): """ Build the action buttons for the contents view based on the current state and the persmissions of the user. :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)]
def contents_buttons(context, request): """ Build the action buttons for the contents view based on the current state and the persmissions of the user. :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)]
def workflow_change(context, request): """Handle workflow change requests from workflow dropdown """ new_state = request.params['new_state'] wf = get_workflow(context) wf.transition_to_state(context, request, new_state) request.session.flash(EditFormView.success_message, 'success') return HTTPFound(location=request.resource_url(context))
def test_workflow_new_content(self, root, workflow, events): from kotti.workflow import get_workflow content = self.make_document(root) wf = get_workflow(content) assert wf.name == u"simple" assert content.state == u"private" assert content.__acl__[0] == ("Allow", "role:admin", ALL_PERMISSIONS) assert content.__acl__[-1] == ("Deny", "system.Everyone", ALL_PERMISSIONS)
def test_workflow_transition(self, app, root, workflow, events): from kotti.workflow import get_workflow content = self.make_document(root) wf = get_workflow(content) wf.transition_to_state(content, None, u'public') assert content.state == u'public' # test public view (pview) and view permissions ('Allow', 'system.Everyone', u'pview') in content.__acl__ ('Allow', 'system.Everyone', u'view') not in content.__acl__
def test_workflow_new_content(self, root, workflow, events): from kotti.workflow import get_workflow content = self.make_document(root) wf = get_workflow(content) assert wf.name == u'simple' assert content.state == u'private' assert content.__acl__[0] == ('Allow', 'role:admin', ALL_PERMISSIONS) assert content.__acl__[-1] == ('Deny', 'system.Everyone', ALL_PERMISSIONS)
def test_reset_workflow_purge_existing(self, root, workflow, events): from kotti.workflow import get_workflow from kotti.workflow import reset_workflow content = self.make_document(root) wf = get_workflow(content) wf.transition_to_state(content, None, u"public") assert content.state == u"public" reset_workflow(purge_existing=True) assert content.state == u"private"
def test_reset_workflow_purge_existing(self): from kotti.workflow import get_workflow from kotti.workflow import reset_workflow content = self.make_document() wf = get_workflow(content) wf.transition_to_state(content, None, u'public') assert content.state == u'public' reset_workflow(purge_existing=True) assert content.state == u'private'
def test_workflow_transition(self, app, root, workflow, events): from kotti.workflow import get_workflow content = self.make_document(root) wf = get_workflow(content) wf.transition_to_state(content, None, u"public") assert content.state == u"public" # test public view (pview) and view permissions ("Allow", "system.Everyone", u"pview") in content.__acl__ ("Allow", "system.Everyone", u"view") not in content.__acl__
def test_workflow_new_content(self, root, workflow, events): from kotti.workflow import get_workflow content = self.make_document(root) wf = get_workflow(content) assert wf.name == "simple" assert content.state == "private" assert content.__acl__[0] == ("Allow", "role:admin", ALL_PERMISSIONS) assert content.__acl__[-1] == ("Deny", "system.Everyone", ALL_PERMISSIONS)
def test_reset_workflow_purge_existing(self, root, workflow, events): from kotti.workflow import get_workflow from kotti.workflow import reset_workflow content = self.make_document(root) wf = get_workflow(content) wf.transition_to_state(content, None, "public") assert content.state == "public" with patch("kotti.workflow.transaction.commit"): reset_workflow(purge_existing=True) assert content.state == "private"
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()
def test_reset_workflow_purge_existing(self, root, workflow, events): from kotti.workflow import get_workflow from kotti.workflow import reset_workflow content = self.make_document(root) wf = get_workflow(content) wf.transition_to_state(content, None, u'public') assert content.state == u'public' with patch('kotti.workflow.transaction.commit'): reset_workflow(purge_existing=True) assert content.state == u'private'
def kn_content(webtest, kn_populate, root, workflow): from kotti.workflow import get_workflow resp = webtest.get('/add_document') form = resp.forms['deform'] form['title'].value = 'Document 1' form['description'].value = 'This is the first document' resp = form.submit('save') resp = webtest.get('/document-1/add_document') form = resp.forms['deform'] form['title'].value = 'Document 1 1' form['description'].value = 'This is the second document' resp = form.submit('save') wf = get_workflow(root['document-1']); wf.transition_to_state(root['document-1'], None, u'public') wf = get_workflow(root['document-1']['document-1-1']); wf.transition_to_state(root['document-1']['document-1-1'], None, u'public')
def test_workflow_new_content(self): from kotti.workflow import get_workflow content = self.make_document() wf = get_workflow(content) assert wf.name == u'simple' assert content.state == u'private' assert content.__acl__[0] == ( 'Allow', 'role:admin', ALL_PERMISSIONS) assert content.__acl__[-1] == ( 'Deny', 'system.Everyone', ALL_PERMISSIONS)
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()
def on_company_insert(event): log.info("YPCompany insert") wf = get_workflow(event.object) if has_permission('state_change', event.object, event.request): wf.transition(event.object, event.request, 'created_to_public') elif has_permission('submit', event.object, event.request): wf.transition(event.object, event.request, 'created_to_pending') else: log.warn("Company created, but no transition allowed for current user.")
def test_reset_workflow(self, root, workflow, events): from kotti.workflow import get_workflow from kotti.workflow import reset_workflow content = self.make_document(root) wf = get_workflow(content) wf.transition_to_state(content, None, u"public") assert content.state == u"public" save_acl = content.__acl__ content.__acl__ = [] reset_workflow() assert content.state == u"public" assert len(content.__acl__) == len(save_acl)
def test_reset_workflow(self): from kotti.workflow import get_workflow from kotti.workflow import reset_workflow content = self.make_document() wf = get_workflow(content) wf.transition_to_state(content, None, u'public') assert content.state == u'public' save_acl = content.__acl__ content.__acl__ = [] reset_workflow() assert content.state == u'public' assert len(content.__acl__) == len(save_acl)
def populate(): if DBSession.query(Node).count() == 0: root = Document(**_ROOT_ATTRS) root.__acl__ = SITE_ACL DBSession.add(root) root['about'] = Document(**_ABOUT_ATTRS) wf = get_workflow(root) if wf is not None: DBSession.flush() # Initializes workflow wf.transition_to_state(root, None, u'public') populate_users()
def populate_root_document(): if DBSession.query(Node).count() == 0: root = Document(name=u'', title=u'Front Page') root.__acl__ = SITE_ACL root.default_view = 'front-page' DBSession.add(root) url = JOB_CONTAINERS['url'] root[url] = Document(title=u'Job Containers', owner=u'admin') set_groups(u'admin', root[url], set([u'role:owner'])) wf = get_workflow(root) if wf is not None: DBSession.flush() # Initializes workflow wf.transition_to_state(root, None, u'public')
def test_workflow_new_content(self, app, root, workflow, events): from kotti.workflow import get_workflow from pyramid.security import ALL_PERMISSIONS content = self.make_document(root) wf = get_workflow(content) assert wf.name == u"simple_backend" assert content.state == u"private" assert content.__acl__[0] == ("Allow", "role:admin", ALL_PERMISSIONS) assert content.__acl__[-1] == ("Deny", "system.Everyone", ALL_PERMISSIONS) # test public view (pview) and view permissions ("Allow", "system.Everyone", u"pview") not in content.__acl__ ("Allow", "system.Everyone", u"view") not in content.__acl__
def test_reset_workflow(self, root, workflow, events): from kotti.workflow import get_workflow from kotti.workflow import reset_workflow content = self.make_document(root) wf = get_workflow(content) wf.transition_to_state(content, None, u'public') assert content.state == u'public' save_acl = content.__acl__ content.__acl__ = [] with patch('kotti.workflow.transaction.commit'): reset_workflow() assert content.state == u'public' assert len(content.__acl__) == len(save_acl)
def test_reset_workflow(self, root, workflow, events): from kotti.workflow import get_workflow from kotti.workflow import reset_workflow content = self.make_document(root) wf = get_workflow(content) wf.transition_to_state(content, None, "public") assert content.state == "public" save_acl = content.__acl__ content.__acl__ = [] with patch("kotti.workflow.transaction.commit"): reset_workflow() assert content.state == "public" assert len(content.__acl__) == len(save_acl)
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')
def workflow(context, request): """Drop down menu for workflow actions. """ wf = get_workflow(context) if wf is not None: state_info = _eval_titles(wf.state_info(context, request)) curr_state = [i for i in state_info if i['current']][0] trans_info = wf.get_transitions(context, request) return { 'states': dict([(i['name'], i) for i in state_info]), 'transitions': trans_info, 'current_state': curr_state, } return {'current_state': None}
def test_workflow_new_content(self, app, root, workflow, events): from kotti.workflow import get_workflow from pyramid.security import ALL_PERMISSIONS content = self.make_document(root) wf = get_workflow(content) assert wf.name == u'simple_backend' assert content.state == u'private' assert content.__acl__[0] == ('Allow', 'role:admin', ALL_PERMISSIONS) assert content.__acl__[-1] == ('Deny', 'system.Everyone', ALL_PERMISSIONS) # test public view (pview) and view permissions ('Allow', 'system.Everyone', u'pview') not in content.__acl__ ('Allow', 'system.Everyone', u'view') not in content.__acl__
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 = wf.get_transitions(context, request) return {"states": _states(context, request), "transitions": trans_info, "current_state": curr_state} return {"current_state": None}
def test_public_document_anonymous(self, root, webtest, db_session): doc = self.make_document(root) assert doc.state == 'private' resp = webtest.get('/doc', headers={'Accept': '*/json'}, status=404) # the document is private assert resp.status_code == 404 # the document is public from kotti.workflow import get_workflow wf = get_workflow(root) wf.transition_to_state(doc, None, u'public') assert doc.state == u'public' resp = webtest.get('/doc', headers={'Accept': '*/json'}, status=404) assert resp.status_code == 404
def workflow(context, request): """Drop down menu for workflow actions. """ wf = get_workflow(context) if wf is not None: state_info = _eval_titles(wf.state_info(context, request)) curr_state = [i for i in state_info if i['current']][0] trans_info = wf.get_transitions(context, request) return { 'states': dict([(i['name'], i) for i in state_info]), 'transitions': trans_info, 'current_state': curr_state, } return { 'current_state': None }
def populate(): """ Create the root node (:class:`~kotti.resources.Document`) and the 'about' subnode in the nodes tree if there are no nodes yet. """ if DBSession.query(Node).count() == 0: root = Document(**_ROOT_ATTRS) root.__acl__ = SITE_ACL DBSession.add(root) root['about'] = Document(**_ABOUT_ATTRS) wf = get_workflow(root) if wf is not None: DBSession.flush() # Initializes workflow wf.transition_to_state(root, None, u'public') populate_users()
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 = wf.get_transitions(context, request) return { 'states': _states(context, request), 'transitions': trans_info, 'current_state': curr_state, } return {'current_state': None}
def test_public_document_anonymous(self, root, webtest, db_session): doc = self.make_document(root) assert doc.state == 'private' resp = webtest.get('/doc', headers={'Accept': '*/json'}, status=403) # the document is private assert resp.status_code == 403 assert 'substancek_cms_theme' in resp.body assert 'MyDocument' not in resp.body # the document is public from kotti.workflow import get_workflow wf = get_workflow(root) wf.transition_to_state(doc, None, u'public') assert doc.state == u'public' resp = webtest.get('/doc', headers={'Accept': '*/json'}, status=200) assert resp.status_code == 200 assert 'substancek_cms_theme' in resp.body assert 'MyDocument' in resp.body
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}
def _state_info(context, request): wf = get_workflow(context) state_info = [] if wf is not None: state_info = _eval_titles(wf.state_info(context, request)) return state_info
def test_private_workflow_name(self, app, root): doc = self.make_document(root) from kotti.workflow import get_workflow wf = get_workflow(doc) assert wf.name == u'private_workflow'
def test_workflow_root(self, root, workflow): from kotti.workflow import get_workflow wf = get_workflow(root) assert wf.name == "simple" assert root.state == "public"
def test_workflow_transition(self): from kotti.workflow import get_workflow content = self.make_document() wf = get_workflow(content) wf.transition_to_state(content, None, u'public') assert content.state == u'public'
def test_workflow_root(self): from kotti.workflow import get_workflow wf = get_workflow(self.root) assert wf.name == u'simple' assert self.root.state == u'public'