def set_element_form_choices(self, form):
     session = self.session
     form.term.choices = term_choice(session)
     form.individual.choices = individual_choice(session, None)  # narrative?
     form.expression_type.choices = expression_type_choice(session)
     form.parent_link_property.choices = property_choice(session)
     return form
 def handle_create_element(self, part_links, parts, req_post):
     logging.info("Hit Element create {0}".format(repr(req_post)))
     claim_id = req_post['claim']
     assert self.ref_id == claim_id, "{0} != {1}".format(repr(self.ref_id), repr(claim_id))
     session = self.session
     claim = session.query(Claim).filter_by(ref_id=claim_id).first()
     # TODO this or req_post['element'] ?
     e_choice = self.int_post_field('element_choice')
     if e_choice:
         parent_element = get_pelement(session, e_choice)
         participant = get_participant(session, parent_element.participant_id)
     else:  # find the participant w/o elements
         participant = self.find_participant_without_elements(claim)
     self.set_claim_form(claim)
     self.set_participant_form(participant, parts)
     form = ElementCreate(req_post)
     form.expression_type.data = "None"
     form.term.choices = term_choice(session)
     form.individual.choices = individual_choice(session, None)  # narrative?
     form.expression_type.choices = expression_type_choice(session)
     form.parent_link_property.choices = property_choice(session)
     form.element_choice.choices = element_choices(session, participant)
     self.element_form = form
     self.update_graph(claim, parts, part_links)
     self.set_hidden_fields(claim_id, participant.ref_id, req_post['element'])
 def handle_commit_element(self, part_links, parts, req_post):
     logging.info("Hit commit element")
     claim_id = req_post['claim']
     assert self.ref_id == claim_id, "{0} != {1}".format(repr(self.ref_id), repr(claim_id))
     session = self.session
     claim = session.query(Claim).filter_by(ref_id=claim_id).first()
     e_choice = self.int_post_field('element_choice')
     if e_choice:
         active_element = get_pelement(session, e_choice)
         participant = active_element.participant
     else:
         participant = self.find_participant_without_elements(claim)
         active_element = None  # best choice here?
     form = ElementCreate(req_post)
     form.element_choice.choices = element_choices(session, participant)
     form = self.set_element_form_choices(form)
     participant_id = participant.ref_id
     if self.enforce_element_type_constraints(form):
         self.report_bad_fields(form)
         logging.info("errors(1): {0}".format(form.errors))
         new_element = ParticipantElement(participant_id=participant_id, old_id=0)
         expression_type = form.expression_type.data
         new_element.expression_type = expression_type
         session.add(new_element)
         transaction.commit()
         element_id = new_element.element_id
         logging.info("New element is {0}".format(repr(element_id)))
         if expression_type == "individual":
             p2i = Pelement2Individual()
             p2i.element = element_id
             p2i.individual = expand_curie(form.individual.data)
             p2i.dummy_id = 0
             session.add(p2i)
         elif expression_type == 'some_term':
             p2t = Pelement2Term()
             p2t.element = element_id
             p2t.term = expand_curie(form.term.data)
             p2t.dummy_id = 0
             session.add(p2t)
             if active_element:
                 plink = ParticipantLink()
                 plink.child = element_id
                 plink.parent = active_element.element_id
                 session.add(plink)
             else:
                 self.update_participant_links(participant_id, element_id)
     else:
         logging.info("errors(2): {0}".format(form.errors))
         form.element_choice.choices = [("None", "None")]
         form.expression_type.choices = expression_type_choice(session)
         form.parent_link_property.choices = property_choice(session)
         element_id = NOELEMENT
     self.set_claim_form(claim)
     participant = get_participant(session, participant_id)
     self.set_participant_form(participant, parts)
     self.element_form = form
     transaction.commit()
     self.update_graph(claim, parts, part_links)
     self.set_hidden_fields(claim_id, participant_id, element_id)
 def finish_participant_form(self, form: (ParticipantEdit, ParticipantCreate), parts):
     """Set choice lists and assign the form as a participant form."""
     session = self.request.dbsession
     form.participation_property.choices = property_choice(session)
     form.type.choices = participant_type_choice(session)
     choices = make_participant_choices(session, parts)
     form.participant_choice.choices = choices
     return form
 def set_participant_form_no_navigator_choices(self, form):
     form.type.choices = participant_type_choice(self.session)
     form.participation_property.choices = property_choice(self.session)