コード例 #1
0
ファイル: app.py プロジェクト: mgruppi/interface_v2
def search_chemistry():
    #basically the same as search samples but with analysis filter options
    if request.args.get("resource") == "chemical_analyses":
        fixedListArgs = combine_identical_parameters(request.args.iteritems(multi=True))
        return redirect(url_for("chemical_analyses")+"?"+urlencode(fixedListArgs))

    if request.args.get("resource") == "sample":
        fixedListArgs = combine_identical_parameters(request.args.iteritems(multi=True))
        return redirect(url_for("samples")+"?"+urlencode(fixedListArgs)+"&chemical_analyses_filters=True")

    # for dynamic field and sorting options
    fields_dict = {'Analysis Method':'analysis_method','Analysis Material':'mineral','Subsample Type':'subsample_type', \
                    'Stage X':'stage_x','Stage Y':'stage_y','Reference':'reference','Reference X':'reference_x','Reference Y':'reference_y', \
                    'Analysis Location':'where_done','Elements':'elements','Oxides':'oxides','Owner':'owner', \
                    'Analyst':'analyst','Analysis Date':'analysis_date','Total':'total'}
    sorting_dict = {'Point':'spot_id','Analysis Method':'analysis_method','Analysis Material':'mineral','Subsample Type':'subsample_type', \
                    'Analysis Location':'where_done','Reference':'reference','Owner':'owner','Analyst':'analyst','Analysis Date':'analysis_date','Total':'total'}

    #Add headers for authentication of 
    oxides = {}
    elements = {}
    minerals = {}
    try:
        headers = {"Authorization":"Token "+session["auth_token"]}
        print "private search chemistry"
        print "header:",headers
        oxides = get(env("API_HOST")+"oxides/", params = {"fields": "species", "page_size": 100, "format": "json"},headers = headers).json()["results"]
        elements = get(env("API_HOST")+"elements/", params = {"fields": "name,symbol", "page_size": 120, "format": "json"},headers=headers).json()["results"]
        minerals = get(env("API_HOST")+"minerals/", params = {"fields": "name", "page_size": 200, "format": "json"},headers = headers).json()["results"]
    except:
        print "public search chemistry"
        headers = {}
        oxides = get(env("API_HOST")+"oxides/", params = {"fields": "species", "page_size": 100, "format": "json"}).json()["results"]
        elements = get(env("API_HOST")+"elements/", params = {"fields": "name,symbol", "page_size": 120, "format": "json"}).json()["results"]
        minerals = get(env("API_HOST")+"minerals/", params = {"fields": "name", "page_size": 200, "format": "json"}).json()["results"]

    return render_template("chemical_search_form.html",
        oxides = oxides,
        elements = elements,
        minerals = minerals,
        fields_dict = sorted(fields_dict),
        fields = sorted(fields_dict.keys()),
        sorting_dict = sorted(sorting_dict),
        auth_token = session.get("auth_token",None),
        email = session.get("email",None),
        name = session.get("name",None)
    )
コード例 #2
0
def search():
    print "search Arguments: ",request.args
    print "session data: ", session
    #get all filter options from API, use format = json and minimum page sizes to speed it up
    if request.args.get("resource") == "samples":
        #resource value set in search_form.html, appends samples.html to bottom of page
        fixedListArgs = combine_identical_parameters(request.args.iteritems(multi=True))
        return redirect(url_for("samples")+"?"+urlencode(fixedListArgs))

    if request.args.get("resource") == "chemical_analyses":
        #minerals_and option not valid parameter for analyses
        #sets sample_filters b/c search samples only has sample filters
        #appends chemical_analyses.html to bottom of page
        fixedListArgs = combine_identical_parameters(request.args.iteritems(multi=True))
        return redirect(url_for("chemical_analyses")+"?"+urlencode(fixedListArgs)+"&sample_filters=True")

    #get all filter options from API, use format = json and minimum page sizes to speed it up
    regions = get(env("API_HOST")+"regions/", params = {"fields": "name", "page_size": 2000, "format": "json"}).json()["results"]
    minerals = get(env("API_HOST")+"minerals/", params = {"fields": "name", "page_size": 200, "format": "json"}).json()["results"]
    rock_types = get(env("API_HOST")+"rock_types/", params = {"fields": "name", "page_size": 40, "format": "json"}).json()["results"]
    collectors = get(env("API_HOST")+"collectors/", params = {"fields": "name", "page_size": 140, "format": "json"}).json()["results"]
    references = get(env("API_HOST")+"references/", params = {"fields": "name", "page_size": 1100, "format": "json"}).json()["results"]
    metamorphic_grades = get(env("API_HOST")+"metamorphic_grades/", params = {"fields": "name", "page_size": 30, "format": "json"}).json()["results"]
    metamorphic_regions = get(env("API_HOST")+"metamorphic_regions/", params = {"fields": "name", "page_size": 240, "format": "json"}).json()["results"]

    countries = get(env("API_HOST")+"country_names/", params = {"format": "json"}).json()["country_names"]
    numbers = get(env("API_HOST")+"sample_numbers/", params = {"format": "json"}).json()["sample_numbers"]
    owners = get(env("API_HOST")+"sample_owner_names/", params = {"format": "json"}).json()["sample_owner_names"]
 
    return render_template("search_form.html",
        regions = regions,
        minerals = minerals,
        rock_types = rock_types,
        collectors = collectors,
        references = references,
        metamorphic_grades = metamorphic_grades,
        metamorphic_regions = metamorphic_regions,
        countries = countries,
        numbers = numbers,
        owners = owners,
        auth_token = session.get("auth_token",None),
        email = session.get("email",None),
        name = session.get("name",None)
    )
コード例 #3
0
def search_chemistry():
    #basically the same as search samples but with analysis filter options
    if request.args.get("resource") == "chemical_analyses":
        fixedListArgs = combine_identical_parameters(request.args.iteritems(multi=True))
        return redirect(url_for("chemical_analyses")+"?"+urlencode(fixedListArgs))

    if request.args.get("resource") == "sample":
        fixedListArgs = combine_identical_parameters(request.args.iteritems(multi=True))
        return redirect(url_for("samples")+"?"+urlencode(fixedListArgs)+"&chemical_analyses_filters=True")
    #Add headers for authentication of 


    oxides = {}
    elements = {}
    minerals = {}
    try:
        headers = {"Authorization":"Token "+session["auth_token"]}
        print "private search chemistry"
        print "HEADER:",headers
        oxides = get(env("API_HOST")+"oxides/", params = {"fields": "species", "page_size": 100, "format": "json"},headers = headers).json()["results"]
        elements = get(env("API_HOST")+"elements/", params = {"fields": "name,symbol", "page_size": 120, "format": "json"},headers=headers).json()["results"]
        minerals = get(env("API_HOST")+"minerals/", params = {"fields": "name", "page_size": 200, "format": "json"},headers = headers).json()["results"]
    except:
        print "public search chemistry"
        headers = {}
        oxides = get(env("API_HOST")+"oxides/", params = {"fields": "species", "page_size": 100, "format": "json"}).json()["results"]
        elements = get(env("API_HOST")+"elements/", params = {"fields": "name,symbol", "page_size": 120, "format": "json"}).json()["results"]
        minerals = get(env("API_HOST")+"minerals/", params = {"fields": "name", "page_size": 200, "format": "json"}).json()["results"]

    print 'len',len(oxides),len(elements),len(minerals)
    return render_template("chemical_search_form.html",
        oxides = oxides,
        elements = elements,
        minerals = minerals,
        auth_token = session.get("auth_token",None),
        email = session.get("email",None),
        name = session.get("name",None)
    )
コード例 #4
0
ファイル: app.py プロジェクト: metpetdb/interface_v2
def search():
    #get all filter options from API, use format = json and minimum page sizes to speed it up
    if request.args.get("resource") == "samples":
        #resource value set in search_form.html, appends samples.html to bottom of page
        fixedListArgs = combine_identical_parameters(request.args.iteritems(multi=True))
        return redirect(url_for("samples")+"?"+urlencode(fixedListArgs))

    if request.args.get("resource") == "chemical_analyses":
        #minerals_and option not valid parameter for analyses
        #sets sample_filters b/c search samples only has sample filters
        #appends chemical_analyses.html to bottom of page
        return redirect(url_for("chemical_analyses")+"?"+urlencode(request.args)+"&sample_filters=True")

    #get all filter options from API, use format = json and minimum page sizes to speed it up
    regions = get(env("API_HOST")+"regions/", params = {"fields": "name", "page_size": 2000, "format": "json"}).json()["results"]
    minerals = get(env("API_HOST")+"minerals/", params = {"fields": "name", "page_size": 200, "format": "json"}).json()["results"]
    rock_types = get(env("API_HOST")+"rock_types/", params = {"fields": "name", "page_size": 40, "format": "json"}).json()["results"]
    collectors = get(env("API_HOST")+"collectors/", params = {"fields": "name", "page_size": 140, "format": "json"}).json()["results"]
    references = get(env("API_HOST")+"references/", params = {"fields": "name", "page_size": 1100, "format": "json"}).json()["results"]
    metamorphic_grades = get(env("API_HOST")+"metamorphic_grades/", params = {"fields": "name", "page_size": 30, "format": "json"}).json()["results"]
    metamorphic_regions = get(env("API_HOST")+"metamorphic_regions/", params = {"fields": "name", "page_size": 240, "format": "json"}).json()["results"]

    countries = get(env("API_HOST")+"country_names/", params = {"format": "json"}).json()["country_names"]
    numbers = get(env("API_HOST")+"sample_numbers/", params = {"format": "json"}).json()["sample_numbers"]
    owners = get(env("API_HOST")+"sample_owner_names/", params = {"format": "json"}).json()["sample_owner_names"]
 
    return render_template("search_form.html",
        regions = regions,
        minerals = minerals,
        rock_types = rock_types,
        collectors = collectors,
        references = references,
        metamorphic_grades = metamorphic_grades,
        metamorphic_regions = metamorphic_regions,
        countries = countries,
        numbers = numbers,
        owners = owners,
        auth_token = session.get("auth_token",None),
        email = session.get("email",None),
        name = session.get("name",None)
    )
コード例 #5
0
ファイル: app.py プロジェクト: metpetdb/interface_v2
def search_chemistry():
    #basically the same as search samples but with analysis filter options
    if request.args.get("resource") == "chemical_analyses":
        return redirect(url_for("chemical_analyses")+"?"+urlencode(request.args))

    if request.args.get("resource") == "sample":
        fixedListArgs = combine_identical_parameters(request.args.iteritems(multi=True))
        return redirect(url_for("samples")+"?"+urlencode(fixedListArgs)+"&chemical_analyses_filters=True")

    oxides = get(env("API_HOST")+"oxides/", params = {"fields": "species", "page_size": 100, "format": "json"}).json()["results"]
    elements = get(env("API_HOST")+"elements/", params = {"fields": "name,symbol", "page_size": 120, "format": "json"}).json()["results"]
    minerals = get(env("API_HOST")+"minerals/", params = {"fields": "name", "page_size": 200, "format": "json"}).json()["results"]

    return render_template("chemical_search_form.html",
        oxides = oxides,
        elements = elements,
        minerals = minerals,
        auth_token = session.get("auth_token",None),
        email = session.get("email",None),
        name = session.get("name",None)
    )
コード例 #6
0
ファイル: app.py プロジェクト: mgruppi/interface_v2
def search():
    filters = dict(request.args)
    print "Search arguments: ", request.args
    print "Session data: ", session
    #get all filter options from API, use format = json and minimum page sizes to speed it up
    if request.args.get("resource") == "samples":
        #resource value set in search_form.html, appends samples.html to bottom of page
        fixedListArgs = combine_identical_parameters(request.args.iteritems(multi=True))
        # Decode utf before encoding as url
        for k,v in fixedListArgs.iteritems():
            if isinstance(v, unicode):
                v = v.encode("utf8")
            elif isinstance(v, str):
                v.decode("utf8")
            fixedListArgs[k] = v

        return redirect(url_for("samples")+"?"+urlencode(fixedListArgs))

    if request.args.get("resource") == "chemical_analyses":
        #minerals_and option not valid parameter for analyses
        #sets sample_filters b/c search samples only has sample filters
        #appends chemical_analyses.html to bottom of page
        fixedListArgs = combine_identical_parameters(request.args.iteritems(multi=True))
        return redirect(url_for("chemical_analyses")+"?"+urlencode(fixedListArgs)+"&sample_filters=True")

    my_samples = None
    if "my_samples" in filters:
        my_samples = get(env("API_HOST")+"samples/?&emails="+session.get("email", None), params={"format":"json"}).json()

    #get all filter options from API, use format = json and minimum page sizes to speed it up
    regions = get(env("API_HOST")+"regions/", params = {"fields": "name", "page_size": 2000, "format": "json"}).json()["results"]
    minerals = get(env("API_HOST")+"minerals/", params = {"fields": "name", "page_size": 200, "format": "json"}).json()["results"]
    rock_types = get(env("API_HOST")+"rock_types/", params = {"fields": "name", "page_size": 40, "format": "json"}).json()["results"]
    # collectors = get(env("API_HOST")+"collectors/", params = {"fields": "name", "page_size": 140, "format": "json"}).json()["results"]
    # references = get(env("API_HOST")+"references/", params = {"fields": "name", "page_size": 2000, "format": "json"}).json()["results"]
    metamorphic_grades = get(env("API_HOST")+"metamorphic_grades/", params = {"fields": "name", "page_size": 30, "format": "json"}).json()["results"]
    metamorphic_regions = get(env("API_HOST")+"metamorphic_regions/", params = {"fields": "id,name,shape", "page_size": 240, "format": "json"}).json()["results"]
    fields_dict = {'Subsamples':'subsample_ids', 'Chemical Analyses':'chemical_analyses_ids', 'Collector':'collector_name', 'Images':'images', 'Owner':'owner', 'Regions':'regions', \
                'Country':'country','Metamorphic Grades':'metamorphic_grades', 'Metamorphic Regions':'metamorphic_regions', 'Minerals':'minerals', \
                'References':'references','Latitude':'latitude', 'Longitude':'longitude', 'Collection Date':'collection_date', 'Rock Type':'rock_type'}
    sorting_dict = {'Sample Number':'number','Subsamples':'subsamples', 'Collection Date':'collection_date','Subsamples':'subsamples', 'Country':'country', \
                'Images':'images','Metamorphic Grades':'metamorphic_grades','Owner':'owner__name', 'References':'references__name', \
                'Rock Type':'rock_type__name', \
                'Chemical Analyses':'chemical_analyses'}
    countries = get(env("API_HOST")+"country_names/", params = {"format": "json"}).json()["country_names"]
    # numbers = get(env("API_HOST")+"sample_numbers/", params = {"format": "json"}).json()["sample_numbers"]
    # owners = get(env("API_HOST")+"sample_owner_names/", params = {"format": "json"}).json()["sample_owner_names"]
    # my_samples = filters['my_samples'] if 'my_samples' in filters else False

    # Filter antarctica which is currently glitched
    metamorphic_regions = [x for x in metamorphic_regions if x["id"] != "091577af-4592-405c-b63e-5b8ecdc69264"]

    # clean up metamorphic_regions shapes
    polygons = {}
    for i in range(len(metamorphic_regions)):
        polygons[metamorphic_regions[i]["id"]] = {"name": metamorphic_regions[i]["name"], "shape": extract_points_from_shape(metamorphic_regions[i]["shape"])}

    return render_template("search_form.html",
        regions = regions,
        minerals = minerals,
        rock_types = rock_types,
        polygons=polygons,
        metamorphic_grades = metamorphic_grades,
        metamorphic_regions = metamorphic_regions,
        sorting_dict = sorted(sorting_dict),
        fields = sorted(fields_dict.keys()),
        countries = countries,
        # numbers = sorted(numbers),
        my_samples = my_samples,
        # owners = sorted(set(owners)),
        auth_token = session.get("auth_token",None),
        email = session.get("email",None),
        name = session.get("name",None)
    )