def objectStateChanged(self, object, event): comment = event.comment if comment is None: comment = u"" else: if hasattr(object, 'note') and len(comment) > 1: object.note = comment wf = IWorkflowInfo(object) if hasattr(object, 'status_date'): object.status_date = datetime.now() if event.source: #get human readable titles for workflow state event_title = wf.workflow().workflow.states[event.source].title else: event_title = 'new' event_description = { 'source': event_title, 'destination': wf.workflow().workflow.states[event.destination].title, 'transition': event.transition.title, 'comment': comment } description = (_( u"""%(transition)s : %(comment)s [ transition from %(source)s to %(destination)s ]""" ) % event_description) return self._objectChanged(u'workflow', object, description)
def get_sitting_items(sitting, request, include_actions=False): items = [] if sitting.status in get_states("groupsitting", keys=["draft_agenda", "published_agenda"]): order = "planned_order" else: order = "real_order" schedulings = map(removeSecurityProxy, sitting.items.batch(order_by=order, limit=None)) site_url = url.absoluteURL(getSite(), request) for scheduling in schedulings: item = ProxyFactory(location_wrapped(scheduling.item, sitting)) props = IDCDescriptiveProperties.providedBy(item) and item or IDCDescriptiveProperties(item) discussions = tuple(scheduling.discussions.values()) discussion = discussions and discussions[0] or None truncated_discussion = None if (discussion is not None) and (discussion.body_text is not None): # truncate discussion to first hundred characters t_discussion = discussion.body_text[0:100] try: # truncate discussion to first two lines index = t_discussion.index("<br>") index2 = t_discussion.index("<br>", index + 4) truncated_discussion = t_discussion[0:index2] + "..." except ValueError: truncated_discussion = t_discussion + "..." info = IWorkflowInfo(item, None) state_title = info.workflow().workflow.states[item.status].title record = { "title": props.title, "description": props.description, "name": stringKey(scheduling), "status": item.status, "type": item.type.capitalize, "t": item.type, "state_title": state_title, #'category_id': scheduling.category_id, #'category': scheduling.category, "discussion": discussion, "truncated_discussion": truncated_discussion, "delete_url": "%s/delete" % url.absoluteURL(scheduling, request), "url": url.set_url_context(site_url + ("/business/%ss/obj-%s" % (item.type, item.parliamentary_item_id))), } if include_actions: record["actions"] = get_scheduling_actions(scheduling, request) record["workflow"] = get_workflow_actions(item, request) discussion_actions = get_discussion_actions(discussion, request) if discussion_actions: assert len(discussion_actions) == 1 record["discussion_action"] = discussion_actions[0] else: record["discussion_action"] = None items.append(record) return items
def get_sitting_items(sitting, request, include_actions=False): items = [] if sitting.status in [ sitting_wf_state[u'draft-agenda'].id, sitting_wf_state[u'published-agenda'].id ]: order = "planned_order" else: order = "real_order" schedulings = map(removeSecurityProxy, sitting.items.batch(order_by=order, limit=None)) for scheduling in schedulings: item = ProxyFactory(location_wrapped(scheduling.item, sitting)) props = IDCDescriptiveProperties.providedBy(item) and item or \ IDCDescriptiveProperties(item) discussions = tuple(scheduling.discussions.values()) discussion = discussions and discussions[0] or None info = IWorkflowInfo(item, None) state_title = info.workflow().workflow.states[item.status].title record = { 'title': props.title, 'description': props.description, 'name': stringKey(scheduling), 'status': item.status, 'type': item.type.capitalize, 't': item.type, 'state_title': state_title, #'category_id': scheduling.category_id, #'category': scheduling.category, 'discussion': discussion, 'delete_url': "%s/delete" % ui_url.absoluteURL(scheduling, request), 'url': ui_url.absoluteURL(item, request) } if include_actions: record['actions'] = get_scheduling_actions(scheduling, request) record['workflow'] = get_workflow_actions(item, request) discussion_actions = get_discussion_actions(discussion, request) if discussion_actions: assert len(discussion_actions) == 1 record['discussion_action'] = discussion_actions[0] else: record['discussion_action'] = None items.append(record) return items
def handleSchedule(object, event): """ move scheduled items from to be scheduled state to schedule when draft agenda is finalised and vice versa""" session = Session() s = removeSecurityProxy(object) sitting = session.query(domain.GroupSitting).options( eagerload('sitting_type'), eagerload('item_schedule')).get(s.sitting_id) schedulings = map(removeSecurityProxy, sitting.item_schedule) if sitting.status == "draft_agenda": for sch in schedulings: if sch.item.type != "heading": wf_info = IWorkflowInfo(sch.item) transitions = wf_info.getSystemTransitionIds() state = wf_info.state() wf = wf_info.workflow() next_state = get_states(sch.item.type, tagged=["tobescheduled"]) for transition_id in transitions: t = wf.getTransition(state.getState(), transition_id) if t.destination in next_state: #TODO find out why firetransition fails for reschedule even #when the user has requisite permissions wf_info.fireTransition(transition_id, check_security=False) break elif sitting.status == "published_agenda": for sch in schedulings: if sch.item.type != "heading": wf_info = IWorkflowInfo(sch.item) transitions = wf_info.getSystemTransitionIds() state = wf_info.state() wf = wf_info.workflow() next_state = get_states(sch.item.type, tagged=["scheduled"]) for transition_id in transitions: t = wf.getTransition(state.getState(), transition_id) if t.destination in next_state: wf_info.fireTransition(transition_id, check_security=False) break
def get_sitting_items(sitting, request, include_actions=False): items = [] if sitting.status in get_states("groupsitting", keys=["draft_agenda", "published_agenda"]): order = "planned_order" else: order = "real_order" schedulings = map( removeSecurityProxy, sitting.items.batch(order_by=order, limit=None)) site_url = url.absoluteURL(getSite(), request) for scheduling in schedulings: item = ProxyFactory(location_wrapped(scheduling.item, sitting)) props = IDCDescriptiveProperties.providedBy(item) and item or \ IDCDescriptiveProperties(item) discussions = tuple(scheduling.discussions.values()) discussion = discussions and discussions[0] or None info = IWorkflowInfo(item, None) state_title = info.workflow().workflow.states[item.status].title record = { 'title': props.title, 'description': props.description, 'name': stringKey(scheduling), 'status': item.status, 'type': item.type.capitalize, 't':item.type, 'state_title': state_title, #'category_id': scheduling.category_id, #'category': scheduling.category, 'discussion': discussion, 'delete_url': "%s/delete" % url.absoluteURL(scheduling, request), 'url': url.set_url_context(site_url+('/business/%ss/obj-%s' % (item.type, item.parliamentary_item_id)))} if include_actions: record['actions'] = get_scheduling_actions(scheduling, request) record['workflow'] = get_workflow_actions(item, request) discussion_actions = get_discussion_actions(discussion, request) if discussion_actions: assert len(discussion_actions) == 1 record['discussion_action'] = discussion_actions[0] else: record['discussion_action'] = None items.append(record) return items
def handleSchedule(object, event): """ move scheduled items from to be scheduled state to schedule when draft agenda is finalised and vice versa """ session = Session() s = removeSecurityProxy(object) sitting = session.query(domain.GroupSitting ).options(eagerload("group_sitting_type"), eagerload("item_schedule") ).get(s.group_sitting_id) schedulings = map(removeSecurityProxy, sitting.item_schedule) if sitting.status == "draft_agenda": for sch in schedulings: if sch.item.type != "heading": wf_info = IWorkflowInfo(sch.item) transitions = wf_info.getSystemTransitionIds() state = wf_info.state() wf = wf_info.workflow() next_state = get_states(sch.item.type, tagged=["tobescheduled"]) for transition_id in transitions: t = wf.getTransition(state.getState(), transition_id) if t.destination in next_state: #TODO find out why firetransition fails for reschedule even #when the user has requisite permissions wf_info.fireTransition(transition_id, check_security=False) break elif sitting.status == "published_agenda": for sch in schedulings: if sch.item.type != "heading": wf_info = IWorkflowInfo(sch.item) transitions = wf_info.getSystemTransitionIds() state = wf_info.state() wf = wf_info.workflow() next_state = get_states(sch.item.type, tagged=["scheduled"]) for transition_id in transitions: t = wf.getTransition(state.getState(), transition_id) if t.destination in next_state: wf_info.fireTransition(transition_id, check_security=False) break
def extra(self): info = IWorkflowInfo(self.context, None) if info is None: return {"id": "plone-contentmenu-workflow"} state = info.state().getState() stateTitle = translate( str(info.workflow().workflow.states[state].title), domain="bungeni.core", context=self.request) return {"id" : "plone-contentmenu-workflow", "class" : "state-%s" % state, "state" : state, "stateTitle" : stateTitle,} # TODO: should be translated
def objectStateChanged( self, object, event): comment = event.comment if comment is None: comment =u"" else: if hasattr(object, 'note') and len(comment)>1: object.note = comment wf = IWorkflowInfo(object) if hasattr(object, 'status_date'): object.status_date = datetime.now() if event.source: #get human readable titles for workflow state event_title = wf.workflow().workflow.states[event.source].title else: event_title = 'new' event_description={ 'source': event_title, 'destination': wf.workflow().workflow.states[event.destination].title, 'transition': event.transition.title, 'comment': comment } description = (_(u"""%(transition)s : %(comment)s [ transition from %(source)s to %(destination)s ]""") %event_description ) return self._objectChanged(u'workflow', object, description )
def extra(self): info = IWorkflowInfo(self.context, None) if info is None: return {'id': 'plone-contentmenu-workflow'} state = info.state().getState() stateTitle = translate( str(info.workflow().workflow.states[state].title), domain="bungeni.core", context=self.request) return {'id' : 'plone-contentmenu-workflow', 'class' : 'state-%s' % state, 'state' : state, 'stateTitle' : stateTitle,} # TODO: should be translated
def extra(self): info = IWorkflowInfo(self.context, None) if info is None: return {"id": "plone-contentmenu-workflow"} state = info.state().getState() stateTitle = translate(str( info.workflow().workflow.states[state].title), domain="bungeni.core", context=self.request) return { "id": "plone-contentmenu-workflow", "class": "state-%s" % state, "state": state, "stateTitle": stateTitle, } # TODO: should be translated
def extra(self): info = IWorkflowInfo(self.context, None) if info is None: return {'id': 'plone-contentmenu-workflow'} state = info.state().getState() stateTitle = translate(str( info.workflow().workflow.states[state].title), domain="bungeni.core", context=self.request) return { 'id': 'plone-contentmenu-workflow', 'class': 'state-%s' % state, 'state': state, 'stateTitle': stateTitle, } # TODO: should be translated
def get_sitting_items(sitting, request, include_actions=False): items = [] if sitting.status in get_states("groupsitting", keys=["draft_agenda", "published_agenda"]): order = "planned_order" else: order = "real_order" schedulings = map(removeSecurityProxy, sitting.items.batch(order_by=order, limit=None)) site_url = url.absoluteURL(getSite(), request) for scheduling in schedulings: item = ProxyFactory(location_wrapped(scheduling.item, sitting)) props = IDCDescriptiveProperties.providedBy(item) and item or \ IDCDescriptiveProperties(item) discussions = tuple(scheduling.discussions.values()) discussion = discussions and discussions[0] or None truncated_discussion = None if ((discussion is not None) and (discussion.body_text is not None)): #truncate discussion to first hundred characters t_discussion = discussion.body_text[0:100] try: #truncate discussion to first two lines index = t_discussion.index("<br>") index2 = t_discussion.index("<br>", index + 4) truncated_discussion = t_discussion[0:index2] + "..." except ValueError: truncated_discussion = t_discussion + "..." info = IWorkflowInfo(item, None) state_title = info.workflow().workflow.states[item.status].title record = { 'title': props.title, 'description': props.description, 'name': stringKey(scheduling), 'status': item.status, 'type': item.type.capitalize, 't': item.type, 'state_title': state_title, #'category_id': scheduling.category_id, #'category': scheduling.category, 'discussion': discussion, 'truncated_discussion': truncated_discussion, 'delete_url': "%s/delete" % url.absoluteURL(scheduling, request), 'url': url.set_url_context(site_url + ('/business/%ss/obj-%s' % (item.type, item.parliamentary_item_id))) } if include_actions: record['actions'] = get_scheduling_actions(scheduling, request) record['workflow'] = get_workflow_actions(item, request) discussion_actions = get_discussion_actions(discussion, request) if discussion_actions: assert len(discussion_actions) == 1 record['discussion_action'] = discussion_actions[0] else: record['discussion_action'] = None items.append(record) return items