def delete_nodes(self): """ Delete nodes view. Renders either a view to delete multiple nodes or delete the selected nodes 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 'delete_nodes' in self.request.POST: ids = self.request.POST.getall('children-to-delete') if not ids: self.flash(_("Nothing was deleted."), 'info') for id in ids: item = DBSession.query(Node).get(id) self.flash(_('${title} was deleted.', mapping=dict(title=item.title)), 'success') del self.context[item.name] 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 = [] if ids is not None: items = DBSession.query(Node).filter(Node.id.in_(ids)).\ order_by(Node.position).all() return {'items': items, 'states': _states(self.context, self.request)}
def delete_nodes(self): """ Delete nodes view. Renders either a view to delete multiple nodes or delete the selected nodes 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 'delete_nodes' in self.request.POST: ids = self.request.POST.getall('children-to-delete') if not ids: self.flash(_(u"Nothing was deleted."), 'info') for id in ids: item = DBSession.query(Node).get(id) self.flash(_(u'${title} was deleted.', mapping=dict(title=item.title)), 'success') del self.context[item.name] 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 = [] if ids is not None: items = DBSession.query(Node).filter(Node.id.in_(ids)).\ order_by(Node.position).all() return {'items': items, 'states': _states(self.context, self.request)}
def delete_nodes(self): """ Delete nodes view. Renders either a view to delete multiple nodes or delete the selected nodes 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 "delete_nodes" in self.request.POST: ids = self.request.POST.getall("children-to-delete") if not ids: self.request.session.flash(_(u"Nothing deleted."), "info") for id in ids: item = DBSession.query(Node).get(id) self.request.session.flash(_(u"${title} deleted.", mapping=dict(title=item.title)), "success") del self.context[item.name] 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 = [] if ids is not None: items = DBSession.query(Node).filter(Node.id.in_(ids)).order_by(Node.position).all() return {"items": items, "states": _states(self.context, self.request)}
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 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 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 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 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 }