Beispiel #1
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("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":
                wfc = IWorkflowController(sch.item)
                wf = wfc.workflow
                next_state = get_states(sch.item.type,
                                        tagged=["tobescheduled"])
                for transition_id in wfc.getSystemTransitionIds():
                    t = wf.get_transition(transition_id)
                    if t.destination in next_state:
                        #TODO find out why firetransition fails for reschedule even
                        #when the user has requisite permissions
                        wfc.fireTransition(transition_id, check_security=False)
                        break
    elif sitting.status == "published_agenda":
        for sch in schedulings:
            if sch.item.type != "heading":
                wfc = IWorkflowController(sch.item)
                wf = wfc.workflow
                next_state = get_states(sch.item.type, tagged=["scheduled"])
                for transition_id in wfc.getSystemTransitionIds():
                    t = wf.get_transition(transition_id)
                    if t.destination in next_state:
                        wfc.fireTransition(transition_id, check_security=False)
                        break
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":
                wfc = IWorkflowController(sch.item)
                wf = wfc.workflow
                next_state = get_states(sch.item.type, tagged=["tobescheduled"])
                for transition_id in wfc.getSystemTransitionIds():
                    t = wf.get_transition(transition_id)
                    if t.destination in next_state:
                        #TODO find out why firetransition fails for reschedule even 
                        #when the user has requisite permissions
                        wfc.fireTransition(transition_id, check_security=False)
                        break
    elif sitting.status == "published_agenda":
        for sch in schedulings:
            if sch.item.type != "heading":
                wfc = IWorkflowController(sch.item)
                wf = wfc.workflow
                next_state = get_states(sch.item.type, tagged=["scheduled"])
                for transition_id in wfc.getSystemTransitionIds():
                    t = wf.get_transition(transition_id)
                    if t.destination in next_state:
                        wfc.fireTransition(transition_id, check_security=False)
                        break
Beispiel #3
0
 def retract_item(item):
     schedule_feature = feature.get_feature(item, "schedule")
     if schedule_feature is None:
         return
     
     # take back to schedule pending
     wfc = IWorkflowController(item)
     for state in schedule_feature.get_param("schedulable_states"):
         transitions = wfc.getFireableTransitionIdsToward(state)
         if transitions:
             wfc.fireTransition(transitions[0])
             break
Beispiel #4
0
    def retract_item(item):
        schedule_feature = feature.get_feature(item, "schedule")
        if schedule_feature is None:
            return

        # take back to schedule pending
        wfc = IWorkflowController(item)
        for state in schedule_feature.get_param("schedulable_states"):
            transitions = wfc.getFireableTransitionIdsToward(state)
            if transitions:
                wfc.fireTransition(transitions[0])
                break
Beispiel #5
0
    def retract_item(item):
        manager = interfaces.ISchedulingManager(item, None)
        if manager is None:
            return
        wfc = IWorkflowController(item, None)
        if wfc is None:
            return

        #take back to schedule pending
        for state in manager.schedulable_states:
            transitions = wfc.getFireableTransitionIdsToward(state)
            if transitions:
                wfc.fireTransition(transitions[0])
                break
Beispiel #6
0
 def __call__(self):
     transition_id = self.request.get("transition_id", None)
     if transition_id:
         wfc = IWorkflowController(self.context)
         wf = wfc.workflow
         try:
             wf.get_transition(transition_id)
         except InvalidTransitionError:
             self.request.response.setStatus(400)
             return "Invalid Transition"
         try:    
             wfc.fireTransition(transition_id)
         except WorkflowRuntimeError:
             self.request.response.setStatus(400)
             return "Runtime error occured while executing transition"
         self.request.response.setStatus(200)
         return "Success"
     else:
         self.request.response.setStatus(400)
         return "No transition id supplied"
Beispiel #7
0
    def saveSchedule(self):
        session = Session()
        sitting_id = self.sitting.sitting_id
        record_keys = []
        planned_index = 1

        def add_planned_index(obj, index):
            """add planned order key for non text record types
            """
            if not (model_interfaces.IScheduleText.providedBy(obj.item)):
                obj.planned_order = planned_index
                index = index + 1
            return index

        for (index, data_item) in enumerate(self.data):
            real_index = index + 1
            data_schedule_id = data_item.get("schedule_id")
            data_item_id = data_item.get("item_id")
            data_item_type = data_item.get("item_type")
            schedule_item_type = data_item_type
            data_item_text = data_item.get("item_text")
            data_item_wf_status = data_item.get("wf_status")
            
            if not data_item_id:
                # create text record before inserting into schedule
                text_record = domain.AgendaTextRecord(
                    text=data_item_text,
                    record_type = data_item_type,
                    language=get_default_language()
                )
                session.add(text_record)
                session.flush()
                notify(ObjectCreatedEvent(text_record))
                data_item_id = domain.get_mapped_object_id(text_record)
                schedule_item_type = domain.AgendaTextRecord.type
                schedule_record = domain.ItemSchedule(
                    item_id=data_item_id,
                    item_type=schedule_item_type,
                    real_order=real_index,
                    sitting_id=sitting_id
                )
                session.add(schedule_record)
                session.flush()
                notify(ObjectCreatedEvent(schedule_record))
            else:
                if data_schedule_id:
                    current_record = removeSecurityProxy(
                        self.context.get(getItemKey(data_schedule_id))
                    )
                    current_record.real_order = real_index
                    planned_index = add_planned_index(current_record, 
                        planned_index)
                    session.add(current_record)
                    session.flush()
                    notify(ObjectModifiedEvent(current_record))
                    
                    #workflow operations
                    wfc = IWorkflowController(current_record.item, None)
                    if wfc:
                        if wfc and data_item_wf_status:
                            try:
                                wfc.workflow.get_transition(data_item_wf_status)
                                wfc.fireTransition(data_item_wf_status)
                            except InvalidTransitionError:
                                log.error(
                                    "Invalid transition [%s] for object: [%s] ",
                                    data_item_wf_status, current_record
                                )
                        wfc.fireAutomatic()
                    
                    #update text for text records
                    text_record = removeSecurityProxy(current_record.item)
                    if model_interfaces.IScheduleText.providedBy(text_record):
                        schedule_item_type = domain.AgendaTextRecord.type
                        if text_record.text != data_item_text:
                            text_record.text = data_item_text
                            session.add(text_record)
                            session.flush()
                            notify(ObjectModifiedEvent(text_record))
                else:
                    schedule_record = domain.ItemSchedule(
                        item_id=data_item_id,
                        item_type=data_item_type,
                        real_order=real_index,
                        sitting_id=sitting_id
                    )
                    planned_index = add_planned_index(schedule_record, 
                        planned_index)
                    session.add(schedule_record)
                    session.flush()
                    notify(ObjectCreatedEvent(schedule_record))
            record_keys.append(self.RECORD_KEY % 
                (schedule_item_type, data_item_id))
        records_to_delete = filter(
            lambda item:(self.RECORD_KEY % (item.item_type, item.item_id)
                not in record_keys
            ),
            [removeSecurityProxy(rec) for rec in self.context.values()]
        )
        map(session.delete, records_to_delete)
        map(lambda deleted:notify(ObjectRemovedEvent(deleted)), 
            records_to_delete)
Beispiel #8
0
    def saveSchedule(self):
        session = Session()
        sitting_id = self.sitting.sitting_id
        record_keys = []
        planned_index = 1

        def add_planned_index(obj, index):
            """add planned order key for non text record types
            """
            if not (model_interfaces.IScheduleText.providedBy(obj.item)):
                obj.planned_order = planned_index
                index = index + 1
            return index

        for (index, data_item) in enumerate(self.data):
            real_index = index + 1
            data_schedule_id = data_item.get("schedule_id")
            data_item_id = data_item.get("item_id")
            data_item_type = data_item.get("item_type")
            schedule_item_type = data_item_type
            data_item_text = data_item.get("item_text")
            data_item_wf_status = data_item.get("wf_status")

            if not data_item_id:
                # create text record before inserting into schedule
                text_record = domain.AgendaTextRecord(
                    text=data_item_text,
                    record_type=data_item_type,
                    language=get_default_language())
                session.add(text_record)
                session.flush()
                notify(ObjectCreatedEvent(text_record))
                data_item_id = domain.get_mapped_object_id(text_record)
                schedule_item_type = domain.AgendaTextRecord.type
                schedule_record = domain.ItemSchedule(
                    item_id=data_item_id,
                    item_type=schedule_item_type,
                    real_order=real_index,
                    sitting_id=sitting_id)
                session.add(schedule_record)
                session.flush()
                notify(ObjectCreatedEvent(schedule_record))
            else:
                if data_schedule_id:
                    current_record = removeSecurityProxy(
                        self.context.get(getItemKey(data_schedule_id)))
                    current_record.real_order = real_index
                    planned_index = add_planned_index(current_record,
                                                      planned_index)
                    session.add(current_record)
                    session.flush()
                    notify(ObjectModifiedEvent(current_record))

                    #workflow operations
                    wfc = IWorkflowController(current_record.item, None)
                    if wfc:
                        if wfc and data_item_wf_status:
                            try:
                                wfc.workflow.get_transition(
                                    data_item_wf_status)
                                wfc.fireTransition(data_item_wf_status)
                            except InvalidTransitionError:
                                log.error(
                                    "Invalid transition [%s] for object: [%s] ",
                                    data_item_wf_status, current_record)
                        wfc.fireAutomatic()

                    #update text for text records
                    text_record = removeSecurityProxy(current_record.item)
                    if model_interfaces.IScheduleText.providedBy(text_record):
                        schedule_item_type = domain.AgendaTextRecord.type
                        if text_record.text != data_item_text:
                            text_record.text = data_item_text
                            session.add(text_record)
                            session.flush()
                            notify(ObjectModifiedEvent(text_record))
                else:
                    schedule_record = domain.ItemSchedule(
                        item_id=data_item_id,
                        item_type=data_item_type,
                        real_order=real_index,
                        sitting_id=sitting_id)
                    planned_index = add_planned_index(schedule_record,
                                                      planned_index)
                    session.add(schedule_record)
                    session.flush()
                    notify(ObjectCreatedEvent(schedule_record))
            record_keys.append(self.RECORD_KEY %
                               (schedule_item_type, data_item_id))
        records_to_delete = filter(
            lambda item: (self.RECORD_KEY %
                          (item.item_type, item.item_id) not in record_keys),
            [removeSecurityProxy(rec) for rec in self.context.values()])
        map(session.delete, records_to_delete)
        map(lambda deleted: notify(ObjectRemovedEvent(deleted)),
            records_to_delete)