示例#1
0
def search(search_terms):
    a = Interaction.objects.all()
    b = Phenotype.objects.all()
    c = Panel.objects.all()
    d = Genotype.objects.all()
    e = Study.objects.all()
    items = chain(a,b,c,d,e)

    # Create model objects from search terms
    results = []
    matches = []
    for item in items:
        list_of_name_value_pairs = [
            (field.name, getattr(item,field.name)) 
            for field in item._meta.fields]
        for li in list_of_name_value_pairs:
            if not (li[0]=='id' or li[0]=='study_id'):
                val = str(li[1]).lower()
                for term in search_terms:
                    if term in val:
                        results.append(item)
                        matches.append(val)
    results = list(set(results))
    
    # Create formSets from model objects
    formSets = utils.get_formsets_from_model_objects(results)
    
    matches = list(set(matches))
    return {'results':formSets,'matches':matches}
示例#2
0
def compile_final_results(results, matches, 
        study_id_to_interaction_id_mapping, interaction_mappings):
    results = list(set(results))
    matches = list(set(matches))
    formSets = utils.get_formsets_from_model_objects(results)
    study_id_to_interaction_id_mapping = (
        clean_study_id_to_interaction_id_mapping(results, 
            study_id_to_interaction_id_mapping))
    # Return final results
    return {'results': formSets, 'matches': matches, 
        'study_id_to_interaction_id_mapping': 
        study_id_to_interaction_id_mapping,
        'interaction_mappings': interaction_mappings}