Exemple #1
0
    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)
Exemple #2
0
def schedule_sitting_items(info, context):
    instance = removeSecurityProxy(context)
    for schedule in instance.item_schedule:
        item = schedule.item
        if interfaces.IQuestion.providedBy(item):
            try:
                IWorkflowInfo(item).fireTransitionToward('scheduled', 
                        check_security=False)
            except NoTransitionAvailableError:
                pass
        elif interfaces.IMotion.providedBy(item):
            try:
                IWorkflowInfo(item).fireTransitionToward('scheduled', 
                        check_security=False)
            except NoTransitionAvailableError:
                pass
        elif interfaces.IAgendaItem.providedBy(item):
            try:
                IWorkflowInfo(item).fireTransitionToward('scheduled', 
                        check_security=False)
            except NoTransitionAvailableError:
                pass
        elif interfaces.ITabledDocument.providedBy(item):
            try:
                IWorkflowInfo(item).fireTransitionToward('scheduled', 
                        check_security=False)
            except NoTransitionAvailableError:
                pass
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
Exemple #4
0
def fireAutomaticTransitions( object, event ):
    """ fire automatic transitions for a new state """
    
    if IWorkflow(object, None) is None:
        return
    
    workflow = IWorkflowInfo(object, None)
    if workflow is not None:
        workflow.fireAutomatic()
Exemple #5
0
def initializeWorkflow( object, event):
    """ in response to object created events """

    if IWorkflow(object, None) is None:
        return
    
    workflow = IWorkflowInfo(object, None)
    if workflow is not None:
        workflow.fireAutomatic()
Exemple #6
0
    def getMenuItems(self, context, request):
        """Return menu item entries in a TAL-friendly form."""
        if interfaces.IBusinessWhatsOnSectionLayer.providedBy(request):
            return ()
        else:
            if IBungeniApplication.providedBy(context.__parent__):
                return ()
        wf = IWorkflow(context, None)
        if wf is None:
            return ()
        #state = IWorkflowInfo(context).state().getState()
        wf_info = IWorkflowInfo(context)
        transitions = wf_info.getManualTransitionIds()

        # !+ context_workflow menu: the order of transitions is alphabetic, but
        # should really be order of definition.
        parliament_id = getCurrentParliamentId()

        url = ui_url.absoluteURL(context, request)
        site_url2 = ui_url.absoluteURL(getSite(), request)
        results = []
        for transition in transitions:
            tid = transition
            state_transition = wf.getTransitionById(transition)
            #Compares the current url to homepage to determine whether we are on workspace or not.
            #Fix for bug 319
            #Someone should probably review this.
            if url == site_url2:
                transition_url = site_url2 + \
                             '/archive/browse/parliaments/obj-' + str(parliament_id) + \
                             '/change_workflow_state?' + \
                             'transition=%s&next_url=...' % tid
            else:
                transition_url = url + \
                             '/change_workflow_state?'\
                             'transition=%s&next_url=...' % tid
            extra = {
                'id': 'workflow-transition-%s' % tid,
                'separator': None,
                'class': ''
            }

            state_title = translate(str(state_transition.title),
                                    domain="bungeni.core",
                                    context=request)
            results.append(
                dict(title=state_title,
                     description="",
                     action=transition_url,
                     selected=False,
                     transition_id=tid,
                     icon=None,
                     extra=extra,
                     submenu=None))

        return results
Exemple #7
0
 def getMenuItems(self, context, request):
     """Return menu item entries in a TAL-friendly form."""
     if interfaces.IBusinessWhatsOnSectionLayer.providedBy(request):
         return ()
     else:
         if IBungeniApplication.providedBy(context.__parent__):
             return ()
     wf = IWorkflow(context, None)
     if wf is None:
         return ()
     #state = IWorkflowInfo(context).state().getState()
     wf_info = IWorkflowInfo(context)
     transitions = wf_info.getManualTransitionIds()
     
     # !+ context_workflow menu: the order of transitions is alphabetic, but 
     # should really be order of definition.
     parliament_id = getCurrentParliamentId()
     
     _url = url.absoluteURL(context, request)
     site_url2 = url.absoluteURL(getSite(), request)
     results = []
     for transition in transitions:
         tid = transition
         state_transition = wf.getTransitionById(transition)
         #Compares the current url to homepage to determine whether we are on workspace or not.
         #Fix for bug 319
         #Someone should probably review this.
         if _url == site_url2:
             transition_url = site_url2 + \
                          "/archive/browse/parliaments/obj-" + str(parliament_id) + \
                          "/change_workflow_state?" + \
                          "transition=%s&next_url=..." % tid
         else:
             transition_url = _url + \
                          "/change_workflow_state?"\
                          "transition=%s&next_url=..." % tid
         extra = {"id": "workflow-transition-%s" % tid,
                  "separator": None,
                  "class": ""}
         
         state_title = translate(str(state_transition.title), 
                 domain="bungeni.core", 
                 context=request)
         results.append(
             dict(title=state_title,
                  description="",
                  action=transition_url,
                  selected=False,
                  transition_id=tid,
                  icon=None,
                  extra=extra,
                  submenu=None))
     
     return results
Exemple #8
0
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 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
Exemple #10
0
 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
Exemple #11
0
 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
Exemple #12
0
    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
Exemple #13
0
    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
Exemple #14
0
 def objectStateChanged(self, object, event):
     """
     object: origin domain workflowed object 
     event: ore.workflow.workflow.WorkflowTransitionEvent
         .object # origin domain workflowed object 
         .source # souirce state
         .destination # destination state
         .transition # transition
         .comment #
     """
     change_data = self._get_change_data()
     # if note, attach it on object (if object supports such an attribute)
     if change_data["note"]:
         if hasattr(object, "note"):
             object.note = change_data["note"]
     # update object's workflow status date (if supported by object)
     if hasattr(object, "status_date"):
         object.status_date = change_data["date_active"] or datetime.now()
     # as a "base" description, use human readable workflow state title
     wf = IWorkflowInfo(object).workflow().workflow
     description = wf.states[event.destination].title
     # extras, that may be used e.g. to elaborate description at runtime
     extras = {
         "source": event.source,
         "destination": event.destination,
         "transition": event.transition.transition_id,
         "comment": change_data["note"]
     }
     return self._objectChanged("workflow",
                                object,
                                description=description,
                                extras=extras,
                                date_active=change_data["date_active"])
Exemple #15
0
 def fireTransitionScheduled(item, check_security=False):
     try:
         IWorkflowInfo(item).fireTransitionToward("scheduled",
                                                  check_security=False)
         raise RuntimeWarning(
             """It has WORKED !!! fireTransitionToward("scheduled")""")
     except (NoTransitionAvailableError, RuntimeWarning):
         debug.log_exc_info(sys.exc_info(), log.error)
def _deferAdmissibleQuestionsBefore(date):
    """
    set all admissible Questions before this
    date to defered
    """
    status = u"admissible"
    admissibleQuestions = _getQuestionsApprovedBefore(date, status)
    for question in admissibleQuestions:
        IWorkflowInfo(question).fireTransitionToward(u'deferred',
                                                     check_security=False)
Exemple #17
0
 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 )
Exemple #18
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
Exemple #19
0
def list_permissions(item):
    wf = IWorkflow(item)
    info = IWorkflowInfo(item)
    state = info.state().getState()
    return tuple(transition.permission 
                for transition in wf.getTransitions(state))
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
Exemple #21
0
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
Exemple #22
0
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
Exemple #23
0
def dissolveChildGroups(groups, context):
    for group in groups:
        IWorkflowInfo(group).fireTransition("active-dissolved",
                                            check_security=False)