def handle_commit_participant(self, req_post): logging.info("Hit 'commit_participant'") ref_id = self.ref_id session = self.session assert req_post['claim'] == ref_id claim = session.query(Claim).filter_by(ref_id=ref_id).first() claim_id = claim.ref_id self.set_claim_form(claim) form = ParticipantCreate(req_post) self.set_participant_form_no_navigator_choices(form) form.participant_choice.data = "None" form.participant_choice.choices = [("None", "None")] form.validate() if form.errors: logging.warning("Participant Create Errors: {0}".format(repr(form.errors))) self.participant_form = form self.element_form = InactiveElementEdit(None) self.set_hidden_fields(claim_id, req_post['participant'], NOELEMENT) else: form = ParticipantEdit(self.request.POST) participant = Participant() new_ref_id = request_uid(self.session) transaction.commit() # maybe not needed participant.ref_id = new_ref_id participant.type = form.type.data participant.label = form.label.data participant.publication_taxon = form.publication_taxon.data participant.publication_anatomy = form.publication_anatomy.data participant.publication_substrate = form.publication_substrate.data participant.publication_text = form.publication_text.data participant.participation_property = expand_curie(form.participation_property.data) participant.claim_id = ref_id parts, part_links, _ = get_participants(self.session, ref_id) parts[participant.ref_id] = participant self.participant_form = form property_key = expand_curie(form.participation_property.data) property_term = session.query(Property).filter_by(ref_id=property_key).one() part_links[participant.ref_id] = property_term self.set_participant_form(participant, parts) self.set_participant_form(participant, parts) self.element_form = ElementCreateOnly() self.element_form.expression_type.data = "None" self.element_form.expression_type.choices = expression_type_choice(session) session.add(participant) transaction.commit() self.update_graph(claim, parts, part_links) self.set_hidden_fields(claim_id, new_ref_id, NOELEMENT) logging.info("Exiting commit participant")
def handle_commit_claim(self, req_post): logging.info("Hit 'commit_claim'") scf = ClaimCreate(req_post) self.set_claim_form_choices(scf) if scf.validate(): scf = ClaimEdit(req_post) self.set_claim_form_choices(scf) claim = Claim() new_ref_id = request_uid(self.session) claim.ref_id = new_ref_id claim.publication = expand_curie(scf.publication.data) if scf.narrative.data == "None": claim.narrative = None else: claim.narrative = expand_curie(scf.narrative.data) claim.behavior_term = expand_curie(scf.behavior_term.data) claim.publication_behavior = scf.publication_behavior.data claim.evidence = expand_curie(scf.evidence.data) transaction.commit() # make sure the ref_id is committed first self.session.add(claim) # commit so HTTPFound 'exception' doesn't drop transaction (TODO - is there a better way) transaction.commit() logging.info("About to redirect to {0}".format(generate_route_id(self.request, 'claim_edit', new_ref_id))) # TODO - can this setup forms and return normally? # self.set_hidden_fields("test claim", "test participant", "test element") return HTTPFound(location=generate_route_id(self.request, 'claim_edit', new_ref_id)) else: session = self.session old_claim_id = req_post['claim'] old_participant_id = req_post['participant'] old_element_id = req_post['element'] parts, part_links, _ = get_participants(session, old_claim_id) self.claim_form = scf participant = parts[old_participant_id] self.set_participant_form(participant, parts) element = session.query(ParticipantElement).filter_by(element_id=old_element_id).one() self.set_element_form(element, element_choices(session, participant)) self.set_hidden_fields(old_claim_id, old_participant_id, old_element_id) return self.render()