def set_claim_form(self, claim):
     """Initialize the edit form that displays the claim itself."""
     post = self.request.POST
     session = self.session
     ref_id = self.ref_id
     logging.info("Checkpoint 5, ref_id is {0}".format(repr(ref_id)))
     if claim.evidence:
         evidence = make_curie(claim.evidence)
         logging.info("Calling make_curie, got {0}".format(evidence))
     else:
         evidence = NOSPEC
     if claim.narrative:
         narrative = make_curie(claim.narrative)
     else:
         narrative = 'None'
     scf = ClaimEdit(post,
                     claim,
                     behavior_label=get_blabel(claim, session))
     scf.behavior_term.data = make_curie(claim.behavior_term)
     scf.evidence.data = evidence
     scf.ref_id = claim.ref_id
     scf.publication.data = make_curie(claim.publication)
     scf.narrative.data = narrative
     scf.narrative.choices = narrative_choice(session, claim.publication)
     scf.publication.choices = publication_choice(session)
     scf.behavior_term.choices = behavior_choice(session)
     scf.evidence.choices = evidence_choice(session)
     self.claim_form = scf
def individual_choice(session, narrative):
    """Generate list of individuals for wtform SelectField.


    """
    if narrative:
        ic = [("None", "None")]
        for i2n in session.query(Individual2Narrative).filter(Individual2Narrative.narrative == narrative):
            ind = session.query(Individual).filter(Individual.ref_id == i2n.individual)
            ic.append((make_curie(ind.ref_id), ind.label[0:CHOICEWIDTH]))
    else:
        ic = [(make_curie(individual.ref_id), individual.label[0:CHOICEWIDTH])
              for individual in session.query(Individual).order_by(Individual.label)]
        ic.insert(0, ("None", "None"))
    return ic
 def choose_participant_form(self, participant, post, parts):
     """Initialize the edit form that displays the participant."""
     form = ParticipantEdit(post)
     form.ref_id = participant.ref_id
     form.participation_property.data = make_curie(participant.participation_property)
     form.type.data = participant.type
     self.participant_form = self.finish_participant_form(form, parts)
 def set_participant_form(self, participant, parts):
     """Initialize the edit form that displays the participant."""
     form = ParticipantEdit(None, participant)
     assert form
     assert participant
     form.ref_id = participant.ref_id
     form.participation_property.data = make_curie(participant.participation_property)
     self.participant_form = self.finish_participant_form(form, parts)
     return self.participant_form
 def choose_element_form(self, post, element, choices):
     """Fill the form from a selected participant element."""
     session = self.session
     sef = ElementEdit(post, element)
     sef.label.data = get_element_label(session, element.element_id)
     parent_prop = parent_property(session, element.element_id)
     if parent_prop:
         sef.parent_link_property.data = make_curie(parent_prop)
     else:
         sef.parent_link_property.data = None
     sef.expression_type.data = element.expression_type
     if element.expression_type == 'individual':
         ind = get_pelements_individual(session, element.element_id)
         sef.individual.data = make_curie(ind)
     elif element.expression_type == 'some_term':
         term = get_pelements_term(session, element.element_id)
         sef.term.data = make_curie(term)
     self.element_form = self.finish_element_form(sef, element, choices)
 def set_element_form(self, element, choices):
     """Initialize the form that displays participant elements."""
     if element is None:
         sef = InactiveElementEdit()
         session = self.request.dbsession
         self.set_element_form_choices(sef)
         sef.element_choice.choices = choices
         sef.individual.choices = individual_choice(session, None)  # need to get narrative
         sef.term.choices = term_choice(session)
         self.element_form = sef
     else:
         session = self.session
         sef = ElementEdit(None, element)
         if element.expression_type == 'individual':
             ind = get_pelements_individual(session, element.element_id)
             sef.individual.data = make_curie(ind)
         elif element.expression_type == 'some_term':
             term = get_pelements_term(session, element.element_id)
             sef.term.data = make_curie(term)
         self.element_form = self.finish_element_form(sef, element, choices)
def narrative_choice(session, pub_id):
    """Generate list of narratives for wtform SelectField.

    Note that this doesn't cache since the db access should be pretty cheap.
    Also note that this is scoped by publication (maybe accept publication=NULL
    for list of everything.
    """
    nc = [(make_curie(narrative.ref_id), narrative.label[0:CHOICEWIDTH])
          for narrative in session.query(Narrative).filter(Narrative.publication == pub_id).order_by(Narrative.label)]
    nc.insert(0, ("None", "None"))
    return nc
def term_choice(session):
    """Generate list of terms for wtform SelectField."""
    global _TERM_CHOICE_CACHE
    if _TERM_CHOICE_CACHE:
        return _TERM_CHOICE_CACHE
    else:
        ta = ['taxonomy', 'anatomy']
        tc = [(make_curie(term.ref_id), term.label[0:CHOICEWIDTH])
              for term in session.query(Term).filter(Term.domain.in_(ta)).order_by(Term.label)]
        _TERM_CHOICE_CACHE = tc
        return tc
def evidence_choice(session):
    """Generate list of evidence types for wtform SelectField."""
    global _EVIDENCE_CHOICE_CACHE
    if _EVIDENCE_CHOICE_CACHE:
        return _EVIDENCE_CHOICE_CACHE
    else:
        ec = [(make_curie(e_term.ref_id), e_term.label[0:CHOICEWIDTH])
              for e_term in session.query(Term).filter_by(domain='evidence').order_by(Term.label)]
        ec.insert(0, (None, NOSPEC))
        _EVIDENCE_CHOICE_CACHE = ec
        return ec
def behavior_choice(session):
    """Generate list of behaviors for wtform SelectField."""
    global _BEHAVIOR_CHOICE_CACHE
    if _BEHAVIOR_CHOICE_CACHE:
        return _BEHAVIOR_CHOICE_CACHE
    else:
        bc = [(make_curie(b_term.ref_id), b_term.label[0:CHOICEWIDTH])
              for b_term in session.query(Term).filter_by(domain='behavior').order_by(Term.label)]
        bc.insert(0, (None, NOSPEC))
        _BEHAVIOR_CHOICE_CACHE = bc
        return bc
def publication_choice(session):
    """Generate list of publications for wtform SelectField."""
    global _PUBLICATION_CHOICE_CACHE
    if _PUBLICATION_CHOICE_CACHE:
        return _PUBLICATION_CHOICE_CACHE
    else:
        pc = [(make_curie(pub.ref_id), pub.make_citation()[0:CHOICEWIDTH])
              for pub in session.query(Publication).order_by(Publication.author_list)]
        pc.insert(0, (None, NOSPEC))
        _PUBLICATION_CHOICE_CACHE = pc
        return pc
def property_choice(session):
    """Generate list of properties for wtform SelectField."""
    global _PROPERTY_CHOICE_CACHE
    if _PROPERTY_CHOICE_CACHE:
        return _PROPERTY_CHOICE_CACHE
    else:
        pc = [(make_curie(prop.ref_id), prop.label)
              for prop in session.query(Property).order_by(Property.label)]
        pc.insert(0, (None, NOSPEC))
        _PROPERTY_CHOICE_CACHE = pc
        return pc
 def test_make_curie(self):
     """Test the conversion from URI to curie."""
     from arachcurator.views.curie_utils import make_curie
     url1 = "http://arachb.org/arachb/ARACHB_000000322"
     curie1 = make_curie(url1)
     self.assertEqual("arachb:ARACHB_000000322", curie1)
     url2 = "http://purl.obolibrary.org/obo/BFO_0000050"
     curie2 = make_curie(url2)
     self.assertEqual("obo:BFO_0000050", curie2)
     url3 = "http://www.w3.org/2002/07/owl#TransitiveProperty"
     curie3 = make_curie(url3)  # should return unchanged
     self.assertEqual(url3, curie3)
     url4 = ""
     curie4 = make_curie(url4)
     self.assertEqual(url4, curie4)
     url5 = "OBO:BFO_0000050"
     make_curie(url5)  # should fail