def new_graph(request): """Function for creating new graph This function allows to creating a new record in the database. """ graph = Graph(name="new graph") graph.save() path_to_graph = "graph/graphs/graph" + str(graph.id) + ".json" to_json = {} with open(path_to_graph, 'w') as f: f.write(json.dumps(to_json)) f.close() graph.path_to_graph = path_to_graph graph.save() return HttpResponse(graph.id)
def graph(request): if request.method == 'GET': print "in get" return HttpResponse("datahdjfhdfhg") if request.method == 'POST': post_data = json.loads(request.body) nodes = post_data.get("nodes") edges = post_data.get("edges") graph_name = post_data.get("graphName") graph = Graph(name=graph_name) graph.save() for link in edges: graph_link = GraphLinks(graph_id=graph.id, link_id=link.get("id")) graph_link.save() response = HttpResponse(json.dumps({"key": "value", "key2": "value"})) response["Access-Control-Allow-Origin"] = "*" response["Access-Control-Allow-Methods"] = "POST, GET, OPTIONS" response["Access-Control-Max-Age"] = "1000" response["Access-Control-Allow-Headers"] = "*" return response
def create_graph(): new_graph = Graph(AdjList={}, pub_date=timezone.now()) new_graph.save() return new_graph.id