Esempio n. 1
0
def substance_search_list(request):
    # print('Hi!')
    # print(request.method)
    if request.method != "GET":
        return False
    top_count = 50  # request.GET['top_count']
    searched = request.GET["q"]

    data = {}
    substance_list = []
    if searched != "":
        subst = request.user.chemistry.substance_get_like(searched, top_count)
        data["total_count"] = subst.count()
        data["incomplete_results"] = False
        for value in subst.values():
            dict_val = {}
            dict_val["id"] = value["id_substance"]
            dict_val["name"] = value["name"]
            dict_val["formula_brutto_formatted"] = value["formula_brutto_formatted"]
            dict_val["formula_brutto"] = value["formula_brutto"]
            lnk = get_subst_detail_link(value["id_substance"])
            dict_val["detail_link"] = make_detail_link(lnk)
            # print(dict_val)
            substance_list.append(dict_val)
    # print(substance_list)
    data["items"] = substance_list
    xml_bytes = json.dumps(data)
    return HttpResponse(xml_bytes, "application/json")
Esempio n. 2
0
def substance_search_hint(request, searched="", top_count=0):
    subst = request.user.chemistry.substance_get_like(searched, top_count)
    tmp = ""
    for value in subst.values():
        if tmp > "":
            tmp = tmp + ", "
        lnk = get_subst_detail_link(value["id_substance"])
        tmp = tmp + make_name_link(lnk, value["name"]) + " (" + value["formula_brutto_formatted"] + ")"
    return HttpResponse(tmp)