def parsepython(request): agreement = request.POST.getlist('termsacceptance') if 'termsacceptance' not in agreement: #Check if user accepted the terms of service warning = {'error': 'error_terms'} json_warning = simplejson.dumps(warning) return HttpResponse(json_warning, mimetype="application/json", status=200) profile_file = request.FILES["profile"] if len(profile_file.name) > 30: #File name was too long. warning = {'error': 'error_length'} json_warning = simplejson.dumps(warning) return HttpResponse(json_warning, mimetype="application/json", status=200) #File needs to be saved because load_stats in pstats.Stats takes a file name #For security, Apache's LimitRequestBody is set to limit file upload size. path = default_storage.save("/home/david/Dropbox/personalprojects/graphi_project/graphi_project/fileuploads/", ContentFile(profile_file.read())) try: p = pstats.Stats(path) except: #Uploaded file was not valid cProfile output. warning = {'error': 'error_output'} json_warning = simplejson.dumps(warning) return HttpResponse(json_warning, mimetype="application/json", status=200) #Validation tests pass. Parse the file and create a json graph with PstatsWriter p = PstatsWriter(path) p.create_nodes_edges_list() p.create_graph() json_graph = simplejson.dumps(p.graph) return HttpResponse(json_graph, mimetype="application/json", status=200)
def parsepython_example(request): #This returns the json for the example on the home page. path = "/home/david/Dropbox/personalprojects/graphi_project/graphi_main/output" p = PstatsWriter(path) p.create_nodes_edges_list() p.create_graph() json_graph = simplejson.dumps(p.graph) return HttpResponse(json_graph, mimetype="application/json", status=200)