def pi_update_signatories(context): """fire automatic transitions on submission of document""" #first commit all pending db transactions for signatory in context.signatories.values(): wfc = IWorkflowController(signatory, None) if wfc is not None: wfc.fireAutomatic()
def _traverse(self, request, name): self.context = removeSecurityProxy(self.context) session = Session() context = session.merge(self.context) debate = session.query(domain.DebateRecord) \ .filter(domain.DebateRecord.sitting_id == context.sitting_id) \ .first() if not debate: debate = domain.DebateRecord() debate.sitting_id = context.sitting_id session.add(debate) wfc = IWorkflowController(debate) wfc.fireAutomatic() session.flush() debate.__name__ = self.traversalName debate.__parent__ = self.context interface.alsoProvides(debate, ILocation) return debate
def _traverse(self, request, name): self.context = removeSecurityProxy(self.context) session = Session() context = session.merge(self.context) debate = session.query(domain.DebateRecord) \ .filter(domain.DebateRecord.sitting_id == context.sitting_id) \ .first() if not debate: debate = domain.DebateRecord() debate.sitting_id = context.sitting_id session.add(debate) wfc = IWorkflowController(debate) wfc.fireAutomatic() session.flush() debate.__name__ = self.traversalName debate.__parent__ = self.context interface.alsoProvides(debate, ILocation) return debate
def on_signatory_doc_workflow_transition(self, context): """Perform any workflow related actions on signatories and/or parent. """ # make (head)context owner a default signatory when doc is submitted to # signatories for consent if self.document_submitted(context): if not self.is_signatory(context, user=context.owner): new_signatory(context.owner_id, context.doc_id) # setup roles for signatory in context.sa_signatories: login = signatory.user.login if self.document_submitted(context): utils.set_role("bungeni.Signatory", login, context) utils.set_role("bungeni.Owner", login, signatory) elif self.auto_unsign(context): utils.unset_role("bungeni.Signatory", login, context) elif self.elapse_signatures(context): if signatory.status not in SIGNATORY_CONSENTED_STATES: utils.unset_role("bungeni.Signatory", login, context) # update signatories for signatory in context.sa_signatories: wfc = IWorkflowController(signatory) wfc.fireAutomatic()
def on_signatory_doc_workflow_transition(self, context): """Perform any workflow related actions on signatories and/or parent. """ # make (head)context owner a default signatory when doc is submitted to # signatories for consent if self.document_submitted(context): if not self.is_signatory(context, user=context.owner): new_signatory(context.owner_id, context.doc_id) # setup roles for signatory in context.sa_signatories: login = signatory.user.login if self.document_submitted(context): utils.set_role("bungeni.Signatory", login, context) utils.set_role("bungeni.Owner", login, signatory) elif self.auto_unsign(context): utils.unset_role("bungeni.Signatory", login, context) elif self.elapse_signatures(context): if signatory.status not in SIGNATORY_CONSENTED_STATES: utils.unset_role("bungeni.Signatory", login, context) # update signatories for signatory in context.sa_signatories: wfc = IWorkflowController(signatory) wfc.fireAutomatic()
def update_signatories(self): for signatory in self.signatories: wfc = IWorkflowController(signatory) wfc.fireAutomatic()
def handle_insert(self, action, data): session = Session() data["rec_end_date"] = data["end_date"] self.template_data = [] initial_sitting = None length = data["event_length"] venue_id = unicode(data["venue"]) if data['venue'] else None if data.get("rec_type") not in [None, "none"]: data["end_date"] = data["start_date"] + timedelta(seconds=length) self.request.form["end_date"] = data["end_date"].strftime(DT_FORMAT) data["headless"] = "true" self.request.form["venue_id"] = data["venue_id"] = venue_id self.request.form["headless"] = "true" add_form = AddForm(self.sittings_container, self.request) add_form.update() if not add_form.errors: initial_sitting = removeSecurityProxy(add_form.created_object) else: return self.insert_sitting_failure_handler(action, data, add_form.errors ) if ("rec_type" in data.keys()) and (data["rec_type"] not in [None, "none"]): # create recurring sittings #base_sitting_length = sitting_length + timedelta(hours=1) sitting_length = timedelta(seconds=length) base_sitting_length = timedelta(seconds=length) + timedelta(hours=1) dates = self.generate_dates(data) initial_sitting.recurring_type = data.get("rec_type") initial_sitting.recurring_id = 0 initial_sitting.sitting_length = length for count, date in enumerate(dates): if not count: #we've already added the initial sitting initial_sitting.recurring_end_date = ( dates[len(dates)-1] + base_sitting_length) session.merge(initial_sitting) continue sitting_data = copy(data) sitting_data["start_date"] = date.strftime(DT_FORMAT) sitting_data["end_date"] = (date + sitting_length).strftime(DT_FORMAT) request_copy = copy(self.request) request_copy.form = sitting_data add_form = AddForm(self.sittings_container, request_copy) add_form.update() if not add_form.errors: # use finishConstruction API here obj = add_form.created_object obj.sitting_length = int(time.mktime(date.timetuple())) obj.recurring_id = initial_sitting.sitting_id session.merge(obj) else: initial_sitting.recurring_type = data.get("rec_type") initial_sitting.recurring_id = data.get("event_pid", 0) if data.get("event_length"): initial_sitting.sitting_length = data.get("event_length") session.merge(initial_sitting) wfc = IWorkflowController(initial_sitting) wfc.fireAutomatic() sitting_action = "inserted" if data["rec_type"] == "none": sitting_action = "deleted" session.merge(initial_sitting) self.template_data.append({ "sitting_id": initial_sitting.sitting_id, "action": sitting_action, "ids": data["ids"], }) self.request.response.setHeader("Content-type", "text/xml") return self.xml_template()
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)
def update_signatories(self): for signatory in self.signatories: wfc = IWorkflowController(signatory) wfc.fireAutomatic()
def handle_insert(self, action, data): session = Session() data["rec_end_date"] = data["end_date"] self.template_data = [] initial_sitting = None length = data["event_length"] venue_id = unicode(data["venue"]) if data['venue'] else None if data.get("rec_type") not in [None, "none"]: data["end_date"] = data["start_date"] + timedelta(seconds=length) self.request.form["end_date"] = data["end_date"].strftime( DT_FORMAT) data["headless"] = "true" self.request.form["venue_id"] = data["venue_id"] = venue_id self.request.form["headless"] = "true" add_form = AddForm(self.sittings_container, self.request) add_form.update() if not add_form.errors: initial_sitting = removeSecurityProxy(add_form.created_object) else: return self.insert_sitting_failure_handler(action, data, add_form.errors) if ("rec_type" in data.keys()) and (data["rec_type"] not in [None, "none"]): # create recurring sittings #base_sitting_length = sitting_length + timedelta(hours=1) sitting_length = timedelta(seconds=length) base_sitting_length = timedelta(seconds=length) + timedelta( hours=1) dates = self.generate_dates(data) initial_sitting.recurring_type = data.get("rec_type") initial_sitting.recurring_id = 0 initial_sitting.sitting_length = length for count, date in enumerate(dates): if not count: #we've already added the initial sitting initial_sitting.recurring_end_date = ( dates[len(dates) - 1] + base_sitting_length) session.merge(initial_sitting) continue sitting_data = copy(data) sitting_data["start_date"] = date.strftime(DT_FORMAT) sitting_data["end_date"] = (date + sitting_length).strftime(DT_FORMAT) request_copy = copy(self.request) request_copy.form = sitting_data add_form = AddForm(self.sittings_container, request_copy) add_form.update() if not add_form.errors: # use finishConstruction API here obj = add_form.created_object obj.sitting_length = int(time.mktime(date.timetuple())) obj.recurring_id = initial_sitting.sitting_id session.merge(obj) else: initial_sitting.recurring_type = data.get("rec_type") initial_sitting.recurring_id = data.get("event_pid", 0) if data.get("event_length"): initial_sitting.sitting_length = data.get("event_length") session.merge(initial_sitting) wfc = IWorkflowController(initial_sitting) wfc.fireAutomatic() sitting_action = "inserted" if data["rec_type"] == "none": sitting_action = "deleted" session.merge(initial_sitting) self.template_data.append({ "sitting_id": initial_sitting.sitting_id, "action": sitting_action, "ids": data["ids"], }) self.request.response.setHeader("Content-type", "text/xml") return self.xml_template()
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)