Exemple #1
0
def APIstructure(request):
    f = jsc.path_to_dict(DATABASE_DIR, DATABASE_DICT_FILE_NAME)
    path = request.GET.get('path', os.sep)
    depth = int(request.GET.get('depth', 3))
    try:
        db = jsc.navigate_path(f, path, False)
    except Exception as e:
        return Response({})
    else:
        truncated_db = jsc.truncate_db(db, depth)
        return Response(truncated_db)
Exemple #2
0
def APIsearch(request):
    """
        gives a list of all path_prefix objects matching search terms
    """
    f = jsc.path_to_dict(DATABASE_DIR, DATABASE_DICT_FILE_NAME)  ####can this be drier? repeated code
    keyword_list = (request.GET.get('query', "")).split()
    path = request.GET.get('path', "/")
    path_prefix = search.get_path_prefix(path)
    try:
        db = jsc.navigate_path(f, path, False)
    except Exception as e:
        print("invalid path")
        return Response({})
    else:
        result = search.search_dic(db, path_prefix, keyword_list)
        return Response({"result": result})