def __init__(self, context, item_type, filter_states=None, group_filter=False, item_filters={}): self.context = context self.item_type = item_type type_info = capi.get_type_info(item_type) self.filter_states = ( filter_states or type_info.workflow.get_state_ids(tagged=["tobescheduled"])) self.group_filter = (group_filter or not IParliament.providedBy(context.group) or IAgendaItem.implementedBy(type_info.domain_model)) try: self.domain_class = get_schedulable_types()[item_type].get( "domain_model") except KeyError: # !+try/except not necessary? try: self.domain_class = type_info.domain_model except KeyError: raise KeyError("Unable to locate domain class for type %s" % item_type) self.item_filters = item_filters
def __init__(self, context, item_type, filter_states=None, group_filter=False, item_filters={} ): self.context = context self.item_type = item_type type_info = capi.get_type_info(item_type) self.filter_states = (filter_states or type_info.workflow.get_state_ids(tagged=["tobescheduled"]) ) self.group_filter = (group_filter or not IParliament.providedBy(context.group) or IAgendaItem.implementedBy(type_info.domain_model) ) try: self.domain_class = get_schedulable_types()[item_type].get( "domain_model") except KeyError: # !+try/except not necessary? try: self.domain_class = type_info.domain_model except KeyError: raise KeyError("Unable to locate domain class for type %s" % item_type ) self.item_filters = item_filters
def get_item_domain(self): domain_class = None try: domain_class = capi.get_type_info(self.item_type).domain_model except KeyError: #!+TYPE REGISTRY(mb, mar-2012) Try to lookup via workflow # demo data not synced with polymorphic prop changes in trunk@r9135 log.debug("Unable to locate type %s from type info lookup." "Trying workflow lookup.", self.item_type ) for type_key, type_info in capi.iter_type_info(): if (type_info.workflow and (type_info.workflow.name == self.item_type) ): domain_class = type_info.domain_model break if domain_class is None: log.error("Unable to locate domain class for item of type %s", self.item_type ) return domain_class
def saveSchedule(self): session = Session() sitting_id = self.sitting.sitting_id group_id = self.sitting.group_id record_keys = [] for (index, data_item) in enumerate(self.data): actual_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") 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 kls = capi.get_type_info(data_item_type).domain_model text_record = kls(text=data_item_text, group_id=group_id, 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_record = domain.ItemSchedule( item_id=data_item_id, item_type=data_item_type, planned_order=actual_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.planned_order = actual_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): 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, planned_order=actual_index, sitting_id=sitting_id, ) session.add(schedule_record) session.flush() notify(ObjectCreatedEvent(schedule_record)) record_keys.append(self.RECORD_KEY % (data_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)