pile_js / Cloud-CV__Origami.jsonl
Hamhams's picture
commit files to HF hub
c7f4bd0
{"nwo":"Cloud-CV\/Origami","sha":"8046898c1afdcc0d32ac3c4a0909f63e2133c3a0","path":"api\/views.py","language":"python","identifier":"redirect_login","parameters":"(req)","argument_list":"","return_statement":"return HttpResponseRedirect(\n '\/login?status=passed&token=' + token.token + '&username=' + user.username + '&user_id=' + str(user.id))","docstring":"Retrieves the token, username and user_id of the user and\n redirects the user to the next page.","docstring_summary":"Retrieves the token, username and user_id of the user and\n redirects the user to the next page.","docstring_tokens":["Retrieves","the","token","username","and","user_id","of","the","user","and","redirects","the","user","to","the","next","page","."],"function":"def redirect_login(req):\n \"\"\"\n Retrieves the token, username and user_id of the user and\n redirects the user to the next page.\n \"\"\"\n user = User.objects.get(username=req.user.username)\n acc = SocialAccount.objects.get(user=user)\n token = SocialToken.objects.get(account=acc)\n if not str(user.id) == acc.uid:\n tmp = user\n user = user.delete()\n tmp.id = acc.uid\n tmp.save()\n acc.user = tmp\n acc.save()\n return HttpResponseRedirect(\n '\/login?status=passed&token=' + token.token + '&username=' + tmp.username + '&user_id=' + str(tmp.id))\n return HttpResponseRedirect(\n '\/login?status=passed&token=' + token.token + '&username=' + user.username + '&user_id=' + str(user.id))","function_tokens":["def","redirect_login","(","req",")",":","user","=","User",".","objects",".","get","(","username","=","req",".","user",".","username",")","acc","=","SocialAccount",".","objects",".","get","(","user","=","user",")","token","=","SocialToken",".","objects",".","get","(","account","=","acc",")","if","not","str","(","user",".","id",")","==","acc",".","uid",":","tmp","=","user","user","=","user",".","delete","(",")","tmp",".","id","=","acc",".","uid","tmp",".","save","(",")","acc",".","user","=","tmp","acc",".","save","(",")","return","HttpResponseRedirect","(","'\/login?status=passed&token='","+","token",".","token","+","'&username='","+","tmp",".","username","+","'&user_id='","+","str","(","tmp",".","id",")",")","return","HttpResponseRedirect","(","'\/login?status=passed&token='","+","token",".","token","+","'&username='","+","user",".","username","+","'&user_id='","+","str","(","user",".","id",")",")"],"url":"https:\/\/github.com\/Cloud-CV\/Origami\/blob\/8046898c1afdcc0d32ac3c4a0909f63e2133c3a0\/api\/views.py#L121-L139"}
{"nwo":"Cloud-CV\/Origami","sha":"8046898c1afdcc0d32ac3c4a0909f63e2133c3a0","path":"api\/views.py","language":"python","identifier":"is_cloudcv","parameters":"(request)","argument_list":"","return_statement":"return Response(serialize.data, status=response_status.HTTP_200_OK)","docstring":"Returns all fields in the current RootSettings object.","docstring_summary":"Returns all fields in the current RootSettings object.","docstring_tokens":["Returns","all","fields","in","the","current","RootSettings","object","."],"function":"def is_cloudcv(request):\n \"\"\"\n Returns all fields in the current RootSettings object.\n \"\"\"\n settings = RootSettings.objects.all().first()\n serialize = RootSettingsSerializer(settings)\n return Response(serialize.data, status=response_status.HTTP_200_OK)","function_tokens":["def","is_cloudcv","(","request",")",":","settings","=","RootSettings",".","objects",".","all","(",")",".","first","(",")","serialize","=","RootSettingsSerializer","(","settings",")","return","Response","(","serialize",".","data",",","status","=","response_status",".","HTTP_200_OK",")"],"url":"https:\/\/github.com\/Cloud-CV\/Origami\/blob\/8046898c1afdcc0d32ac3c4a0909f63e2133c3a0\/api\/views.py#L143-L149"}
{"nwo":"Cloud-CV\/Origami","sha":"8046898c1afdcc0d32ac3c4a0909f63e2133c3a0","path":"api\/views.py","language":"python","identifier":"get_all_user_demos","parameters":"(request, id)","argument_list":"","return_statement":"return Response(serialize.data, status=response_status.HTTP_200_OK)","docstring":"Returns properties of all demos for the\n user identified by the given id.","docstring_summary":"Returns properties of all demos for the\n user identified by the given id.","docstring_tokens":["Returns","properties","of","all","demos","for","the","user","identified","by","the","given","id","."],"function":"def get_all_user_demos(request, id):\n \"\"\"\n Returns properties of all demos for the\n user identified by the given id.\n \"\"\"\n demos = Demo.objects.filter(user_id=id)\n serialize = DemoSerializer(demos, many=True)\n return Response(serialize.data, status=response_status.HTTP_200_OK)","function_tokens":["def","get_all_user_demos","(","request",",","id",")",":","demos","=","Demo",".","objects",".","filter","(","user_id","=","id",")","serialize","=","DemoSerializer","(","demos",",","many","=","True",")","return","Response","(","serialize",".","data",",","status","=","response_status",".","HTTP_200_OK",")"],"url":"https:\/\/github.com\/Cloud-CV\/Origami\/blob\/8046898c1afdcc0d32ac3c4a0909f63e2133c3a0\/api\/views.py#L153-L160"}
{"nwo":"Cloud-CV\/Origami","sha":"8046898c1afdcc0d32ac3c4a0909f63e2133c3a0","path":"api\/views.py","language":"python","identifier":"get_all_demos","parameters":"(request)","argument_list":"","return_statement":"return Response(data, status=response_status.HTTP_200_OK)","docstring":"If the request parameter search_by is demo,\n returns all demos which contains the search_term as a substring,\n otherwise returns all demos belonging to the user having the\n username matching the given search_term.","docstring_summary":"If the request parameter search_by is demo,\n returns all demos which contains the search_term as a substring,\n otherwise returns all demos belonging to the user having the\n username matching the given search_term.","docstring_tokens":["If","the","request","parameter","search_by","is","demo","returns","all","demos","which","contains","the","search_term","as","a","substring","otherwise","returns","all","demos","belonging","to","the","user","having","the","username","matching","the","given","search_term","."],"function":"def get_all_demos(request):\n \"\"\"\n If the request parameter search_by is demo,\n returns all demos which contains the search_term as a substring,\n otherwise returns all demos belonging to the user having the\n username matching the given search_term.\n \"\"\"\n search_by = request.query_params.get('search_by', None)\n search_term = request.query_params.get('search_term', None)\n demos = []\n if search_by == \"demo\":\n demos = Demo.objects.filter(name__icontains=search_term)\n else:\n try:\n user = User.objects.get(username__iexact=search_term)\n demos = Demo.objects.filter(user_id=user.id)\n except User.DoesNotExist:\n demos = []\n serialize = DemoSerializer(demos, many=True)\n data = serialize.data\n for x in range(len(demos)):\n data[x][\"username\"] = User.objects.get(id=data[x][\"user_id\"]).username\n return Response(data, status=response_status.HTTP_200_OK)","function_tokens":["def","get_all_demos","(","request",")",":","search_by","=","request",".","query_params",".","get","(","'search_by'",",","None",")","search_term","=","request",".","query_params",".","get","(","'search_term'",",","None",")","demos","=","[","]","if","search_by","==","\"demo\"",":","demos","=","Demo",".","objects",".","filter","(","name__icontains","=","search_term",")","else",":","try",":","user","=","User",".","objects",".","get","(","username__iexact","=","search_term",")","demos","=","Demo",".","objects",".","filter","(","user_id","=","user",".","id",")","except","User",".","DoesNotExist",":","demos","=","[","]","serialize","=","DemoSerializer","(","demos",",","many","=","True",")","data","=","serialize",".","data","for","x","in","range","(","len","(","demos",")",")",":","data","[","x","]","[","\"username\"","]","=","User",".","objects",".","get","(","id","=","data","[","x","]","[","\"user_id\"","]",")",".","username","return","Response","(","data",",","status","=","response_status",".","HTTP_200_OK",")"],"url":"https:\/\/github.com\/Cloud-CV\/Origami\/blob\/8046898c1afdcc0d32ac3c4a0909f63e2133c3a0\/api\/views.py#L164-L186"}
{"nwo":"Cloud-CV\/Origami","sha":"8046898c1afdcc0d32ac3c4a0909f63e2133c3a0","path":"api\/views.py","language":"python","identifier":"custom_component_controller","parameters":"(request, type_req, user_id, demoid)","argument_list":"","return_statement":"return Response(\"Invalid URL\", status=response_status.HTTP_404_NOT_FOUND)","docstring":"Gets the properties of, adds, updates, or removes an\n InputComponent or OutputComponent given a\n GET, POST, PUT or DELETE request respectively.\n\n Keyword arguments:\n type_req (str): Specifies whether processing is for an\n InputComponent or OutputComponent.\n user_id (str): The id of the user\n demoid (str): The id of the demo","docstring_summary":"Gets the properties of, adds, updates, or removes an\n InputComponent or OutputComponent given a\n GET, POST, PUT or DELETE request respectively.","docstring_tokens":["Gets","the","properties","of","adds","updates","or","removes","an","InputComponent","or","OutputComponent","given","a","GET","POST","PUT","or","DELETE","request","respectively","."],"function":"def custom_component_controller(request, type_req, user_id, demoid):\n \"\"\"\n Gets the properties of, adds, updates, or removes an\n InputComponent or OutputComponent given a\n GET, POST, PUT or DELETE request respectively.\n\n Keyword arguments:\n type_req (str): Specifies whether processing is for an\n InputComponent or OutputComponent.\n user_id (str): The id of the user\n demoid (str): The id of the demo\n \"\"\"\n model = \"\"\n serializer = \"\"\n if type_req == \"input\":\n model = InputComponent\n serializer = InputComponentSerializer\n elif type_req == \"output\":\n model = OutputComponent\n serializer = OutputComponentSerializer\n\n if request.method == \"POST\":\n body = request.data\n demo_id = body[\"id\"]\n demo = Demo.objects.get(id=demo_id)\n base_comp_id = body[\"base_component_id\"]\n props = []\n for prop in body[\"props\"]:\n if prop:\n props.append({\n \"id\": prop[\"id\"].encode(\"ascii\", \"ignore\").decode('utf-8'),\n \"label\": prop[\"label\"].encode(\"ascii\", \"ignore\").decode('utf-8')\n })\n else:\n props.append({})\n user_id = body[\"user_id\"]\n component = model.objects.create(\n demo=demo, base_component_id=base_comp_id, props=json.dumps(props), user_id=user_id)\n serialize = serializer(component)\n return Response(serialize.data, status=response_status.HTTP_201_CREATED)\n elif request.method == \"GET\":\n if user_id:\n if demoid:\n demo = Demo.objects.get(id=demoid)\n try:\n component = model.objects.get(user_id=user_id, demo=demo)\n except Exception:\n return Response({\"text\": \"Not Found\"})\n\n serialize = serializer(component)\n data = serialize.data\n data[\"props\"] = json.loads(data[\"props\"].encode(\"ascii\", \"ignore\").decode('utf8'))\n data[\"demo\"] = DemoSerializer(component.demo).data\n data[\"id\"] = component.demo.id\n return Response([data], status=response_status.HTTP_200_OK)\n else:\n components = model.objects.filter(user_id=user_id)\n serialize = serializer(components, many=True)\n data = serialize.data\n for x in range(len(data)):\n data[x][\"props\"] = json.loads(data[x][\"props\"].encode(\"ascii\", \"ignore\").decode('utf8'))\n data[x][\"demo\"] = DemoSerializer(components[x].demo).data\n data[x][\"id\"] = components[x].demo.id\n return Response(serialize.data, status=response_status.HTTP_200_OK)\n else:\n return Response(\"Invalid URL\", status=response_status.HTTP_404_NOT_FOUND)\n elif request.method == \"PUT\":\n body = request.data\n if user_id and demoid:\n demo = Demo.objects.get(id=demoid)\n component = model.objects.get(demo=demo, user_id=user_id)\n component.base_component_id = body[\"base_component_id\"]\n props = []\n for prop in body[\"props\"]:\n if prop:\n props.append({\n \"id\": prop[\"id\"].encode(\"ascii\", \"ignore\").decode('utf-8'),\n \"label\": prop[\"label\"].encode(\"ascii\", \"ignore\").decode('utf-8')\n })\n else:\n props.append({})\n component.props = json.dumps(props)\n component.save()\n serialize = serializer(component)\n return Response(serialize.data, status=response_status.HTTP_200_OK)\n else:\n return Response(\"Invalid URL\", status=response_status.HTTP_404_NOT_FOUND)\n elif request.method == \"DELETE\":\n if user_id and demoid:\n model.objects.get(id=demoid, user_id=user_id).delete()\n return Response({\"removed\": True}, status=response_status.HTTP_200_OK)\n else:\n return Response(\"Invalid URL\", status=response_status.HTTP_404_NOT_FOUND)\n return Response(\"Invalid URL\", status=response_status.HTTP_404_NOT_FOUND)","function_tokens":["def","custom_component_controller","(","request",",","type_req",",","user_id",",","demoid",")",":","model","=","\"\"","serializer","=","\"\"","if","type_req","==","\"input\"",":","model","=","InputComponent","serializer","=","InputComponentSerializer","elif","type_req","==","\"output\"",":","model","=","OutputComponent","serializer","=","OutputComponentSerializer","if","request",".","method","==","\"POST\"",":","body","=","request",".","data","demo_id","=","body","[","\"id\"","]","demo","=","Demo",".","objects",".","get","(","id","=","demo_id",")","base_comp_id","=","body","[","\"base_component_id\"","]","props","=","[","]","for","prop","in","body","[","\"props\"","]",":","if","prop",":","props",".","append","(","{","\"id\"",":","prop","[","\"id\"","]",".","encode","(","\"ascii\"",",","\"ignore\"",")",".","decode","(","'utf-8'",")",",","\"label\"",":","prop","[","\"label\"","]",".","encode","(","\"ascii\"",",","\"ignore\"",")",".","decode","(","'utf-8'",")","}",")","else",":","props",".","append","(","{","}",")","user_id","=","body","[","\"user_id\"","]","component","=","model",".","objects",".","create","(","demo","=","demo",",","base_component_id","=","base_comp_id",",","props","=","json",".","dumps","(","props",")",",","user_id","=","user_id",")","serialize","=","serializer","(","component",")","return","Response","(","serialize",".","data",",","status","=","response_status",".","HTTP_201_CREATED",")","elif","request",".","method","==","\"GET\"",":","if","user_id",":","if","demoid",":","demo","=","Demo",".","objects",".","get","(","id","=","demoid",")","try",":","component","=","model",".","objects",".","get","(","user_id","=","user_id",",","demo","=","demo",")","except","Exception",":","return","Response","(","{","\"text\"",":","\"Not Found\"","}",")","serialize","=","serializer","(","component",")","data","=","serialize",".","data","data","[","\"props\"","]","=","json",".","loads","(","data","[","\"props\"","]",".","encode","(","\"ascii\"",",","\"ignore\"",")",".","decode","(","'utf8'",")",")","data","[","\"demo\"","]","=","DemoSerializer","(","component",".","demo",")",".","data","data","[","\"id\"","]","=","component",".","demo",".","id","return","Response","(","[","data","]",",","status","=","response_status",".","HTTP_200_OK",")","else",":","components","=","model",".","objects",".","filter","(","user_id","=","user_id",")","serialize","=","serializer","(","components",",","many","=","True",")","data","=","serialize",".","data","for","x","in","range","(","len","(","data",")",")",":","data","[","x","]","[","\"props\"","]","=","json",".","loads","(","data","[","x","]","[","\"props\"","]",".","encode","(","\"ascii\"",",","\"ignore\"",")",".","decode","(","'utf8'",")",")","data","[","x","]","[","\"demo\"","]","=","DemoSerializer","(","components","[","x","]",".","demo",")",".","data","data","[","x","]","[","\"id\"","]","=","components","[","x","]",".","demo",".","id","return","Response","(","serialize",".","data",",","status","=","response_status",".","HTTP_200_OK",")","else",":","return","Response","(","\"Invalid URL\"",",","status","=","response_status",".","HTTP_404_NOT_FOUND",")","elif","request",".","method","==","\"PUT\"",":","body","=","request",".","data","if","user_id","and","demoid",":","demo","=","Demo",".","objects",".","get","(","id","=","demoid",")","component","=","model",".","objects",".","get","(","demo","=","demo",",","user_id","=","user_id",")","component",".","base_component_id","=","body","[","\"base_component_id\"","]","props","=","[","]","for","prop","in","body","[","\"props\"","]",":","if","prop",":","props",".","append","(","{","\"id\"",":","prop","[","\"id\"","]",".","encode","(","\"ascii\"",",","\"ignore\"",")",".","decode","(","'utf-8'",")",",","\"label\"",":","prop","[","\"label\"","]",".","encode","(","\"ascii\"",",","\"ignore\"",")",".","decode","(","'utf-8'",")","}",")","else",":","props",".","append","(","{","}",")","component",".","props","=","json",".","dumps","(","props",")","component",".","save","(",")","serialize","=","serializer","(","component",")","return","Response","(","serialize",".","data",",","status","=","response_status",".","HTTP_200_OK",")","else",":","return","Response","(","\"Invalid URL\"",",","status","=","response_status",".","HTTP_404_NOT_FOUND",")","elif","request",".","method","==","\"DELETE\"",":","if","user_id","and","demoid",":","model",".","objects",".","get","(","id","=","demoid",",","user_id","=","user_id",")",".","delete","(",")","return","Response","(","{","\"removed\"",":","True","}",",","status","=","response_status",".","HTTP_200_OK",")","else",":","return","Response","(","\"Invalid URL\"",",","status","=","response_status",".","HTTP_404_NOT_FOUND",")","return","Response","(","\"Invalid URL\"",",","status","=","response_status",".","HTTP_404_NOT_FOUND",")"],"url":"https:\/\/github.com\/Cloud-CV\/Origami\/blob\/8046898c1afdcc0d32ac3c4a0909f63e2133c3a0\/api\/views.py#L190-L283"}
{"nwo":"Cloud-CV\/Origami","sha":"8046898c1afdcc0d32ac3c4a0909f63e2133c3a0","path":"api\/views.py","language":"python","identifier":"alive","parameters":"(request)","argument_list":"","return_statement":"return HttpResponse(status=200)","docstring":"Returns a status 200 if the server is running and 404 otherwise","docstring_summary":"Returns a status 200 if the server is running and 404 otherwise","docstring_tokens":["Returns","a","status","200","if","the","server","is","running","and","404","otherwise"],"function":"def alive(request):\n \"\"\"Returns a status 200 if the server is running and 404 otherwise\"\"\"\n return HttpResponse(status=200)","function_tokens":["def","alive","(","request",")",":","return","HttpResponse","(","status","=","200",")"],"url":"https:\/\/github.com\/Cloud-CV\/Origami\/blob\/8046898c1afdcc0d32ac3c4a0909f63e2133c3a0\/api\/views.py#L286-L288"}
{"nwo":"Cloud-CV\/Origami","sha":"8046898c1afdcc0d32ac3c4a0909f63e2133c3a0","path":"api\/views.py","language":"python","identifier":"custom_demo_controller","parameters":"(request, user_id, id)","argument_list":"","return_statement":"return Response(\"Invalid URL\", status=response_status.HTTP_404_NOT_FOUND)","docstring":"Gets the properties of, adds, updates, or removes a demo or\n demos given a GET, POST, PUT or DELETE request respectively.\n\n A GET request also returns all sample_inputs belonging to\n the demo if request parameter id is specified.\n A GET request returns all demo objects in the database if\n both the user_id and id of the demo are not specified.\n\n Keyword arguments:\n user_id (str): The id of the user\n id (str): The id of the demo","docstring_summary":"Gets the properties of, adds, updates, or removes a demo or\n demos given a GET, POST, PUT or DELETE request respectively.","docstring_tokens":["Gets","the","properties","of","adds","updates","or","removes","a","demo","or","demos","given","a","GET","POST","PUT","or","DELETE","request","respectively","."],"function":"def custom_demo_controller(request, user_id, id):\n \"\"\"\n Gets the properties of, adds, updates, or removes a demo or\n demos given a GET, POST, PUT or DELETE request respectively.\n\n A GET request also returns all sample_inputs belonging to\n the demo if request parameter id is specified.\n A GET request returns all demo objects in the database if\n both the user_id and id of the demo are not specified.\n\n Keyword arguments:\n user_id (str): The id of the user\n id (str): The id of the demo\n \"\"\"\n if request.method == \"GET\":\n if id and user_id:\n try:\n demo = Demo.objects.get(id=id, user_id=user_id)\n except Exception:\n return Response({\"text\": \"Not Found\"})\n serialize = DemoSerializer(demo).data\n try:\n sample_inputs = SampleInput.objects.filter(demo=demo)\n except Exception:\n sample_inputs = None\n if sample_inputs:\n sample_inputs_serialize = SampleInputSerializer(sample_inputs, many=True).data\n serialize[\"sampleinput\"] = sample_inputs_serialize\n return Response([serialize], status=response_status.HTTP_200_OK)\n elif user_id and not id:\n demos = Demo.objects.filter(user_id=user_id)\n serialize = DemoSerializer(demos, many=True)\n return Response(serialize.data, status=response_status.HTTP_200_OK)\n else:\n demos = Demo.objects.all()\n serialize = DemoSerializer(demos, many=True)\n data = serialize.data\n for x in range(len(demos)):\n data[x][\"username\"] = User.objects.get(id=data[x][\"user_id\"]).username\n return Response(data, status=response_status.HTTP_200_OK)\n elif request.method == \"POST\":\n body = request.data\n name = body[\"name\"]\n id = body[\"id\"]\n user_id = body[\"user_id\"]\n address = body[\"address\"]\n description = body[\"description\"]\n footer_message = body[\"footer_message\"]\n cover_image = body[\"cover_image\"]\n if not cover_image:\n cover_image = DEFAULT_IMAGE\n terminal = body[\"terminal\"]\n timestamp = body[\"timestamp\"]\n token = body[\"token\"]\n status = body[\"status\"]\n demo = Demo.objects.create(\n name=name,\n id=id,\n user_id=user_id,\n address=address,\n description=description,\n footer_message=footer_message,\n cover_image=cover_image,\n terminal=terminal,\n timestamp=timestamp,\n token=token,\n status=status)\n serialize = DemoSerializer(demo)\n return Response(serialize.data, status=response_status.HTTP_201_CREATED)\n\n elif request.method == \"PUT\":\n if id and user_id:\n body = request.data\n demo = Demo.objects.get(id=id, user_id=user_id)\n demo.name = body[\"name\"]\n demo.address = body[\"address\"]\n demo.description = body[\"description\"]\n demo.footer_message = body[\"footer_message\"]\n if not body[\"cover_image\"]:\n demo.cover_image = DEFAULT_IMAGE\n else:\n demo.cover_image = body[\"cover_image\"]\n demo.terminal = body[\"terminal\"]\n demo.token = body[\"token\"]\n demo.status = body[\"status\"]\n demo.save()\n serialize = DemoSerializer(demo)\n return Response(serialize.data, status=response_status.HTTP_200_OK)\n else:\n return Response(\"Invalid URL\", status=response_status.HTTP_404_NOT_FOUND)\n\n elif request.method == \"DELETE\":\n if user_id and id:\n Demo.objects.get(id=id, user_id=user_id).delete()\n return Response({\"removed\": True}, status=response_status.HTTP_200_OK)\n else:\n return Response(\"Invalid URL\", status=response_status.HTTP_404_NOT_FOUND)\n return Response(\"Invalid URL\", status=response_status.HTTP_404_NOT_FOUND)","function_tokens":["def","custom_demo_controller","(","request",",","user_id",",","id",")",":","if","request",".","method","==","\"GET\"",":","if","id","and","user_id",":","try",":","demo","=","Demo",".","objects",".","get","(","id","=","id",",","user_id","=","user_id",")","except","Exception",":","return","Response","(","{","\"text\"",":","\"Not Found\"","}",")","serialize","=","DemoSerializer","(","demo",")",".","data","try",":","sample_inputs","=","SampleInput",".","objects",".","filter","(","demo","=","demo",")","except","Exception",":","sample_inputs","=","None","if","sample_inputs",":","sample_inputs_serialize","=","SampleInputSerializer","(","sample_inputs",",","many","=","True",")",".","data","serialize","[","\"sampleinput\"","]","=","sample_inputs_serialize","return","Response","(","[","serialize","]",",","status","=","response_status",".","HTTP_200_OK",")","elif","user_id","and","not","id",":","demos","=","Demo",".","objects",".","filter","(","user_id","=","user_id",")","serialize","=","DemoSerializer","(","demos",",","many","=","True",")","return","Response","(","serialize",".","data",",","status","=","response_status",".","HTTP_200_OK",")","else",":","demos","=","Demo",".","objects",".","all","(",")","serialize","=","DemoSerializer","(","demos",",","many","=","True",")","data","=","serialize",".","data","for","x","in","range","(","len","(","demos",")",")",":","data","[","x","]","[","\"username\"","]","=","User",".","objects",".","get","(","id","=","data","[","x","]","[","\"user_id\"","]",")",".","username","return","Response","(","data",",","status","=","response_status",".","HTTP_200_OK",")","elif","request",".","method","==","\"POST\"",":","body","=","request",".","data","name","=","body","[","\"name\"","]","id","=","body","[","\"id\"","]","user_id","=","body","[","\"user_id\"","]","address","=","body","[","\"address\"","]","description","=","body","[","\"description\"","]","footer_message","=","body","[","\"footer_message\"","]","cover_image","=","body","[","\"cover_image\"","]","if","not","cover_image",":","cover_image","=","DEFAULT_IMAGE","terminal","=","body","[","\"terminal\"","]","timestamp","=","body","[","\"timestamp\"","]","token","=","body","[","\"token\"","]","status","=","body","[","\"status\"","]","demo","=","Demo",".","objects",".","create","(","name","=","name",",","id","=","id",",","user_id","=","user_id",",","address","=","address",",","description","=","description",",","footer_message","=","footer_message",",","cover_image","=","cover_image",",","terminal","=","terminal",",","timestamp","=","timestamp",",","token","=","token",",","status","=","status",")","serialize","=","DemoSerializer","(","demo",")","return","Response","(","serialize",".","data",",","status","=","response_status",".","HTTP_201_CREATED",")","elif","request",".","method","==","\"PUT\"",":","if","id","and","user_id",":","body","=","request",".","data","demo","=","Demo",".","objects",".","get","(","id","=","id",",","user_id","=","user_id",")","demo",".","name","=","body","[","\"name\"","]","demo",".","address","=","body","[","\"address\"","]","demo",".","description","=","body","[","\"description\"","]","demo",".","footer_message","=","body","[","\"footer_message\"","]","if","not","body","[","\"cover_image\"","]",":","demo",".","cover_image","=","DEFAULT_IMAGE","else",":","demo",".","cover_image","=","body","[","\"cover_image\"","]","demo",".","terminal","=","body","[","\"terminal\"","]","demo",".","token","=","body","[","\"token\"","]","demo",".","status","=","body","[","\"status\"","]","demo",".","save","(",")","serialize","=","DemoSerializer","(","demo",")","return","Response","(","serialize",".","data",",","status","=","response_status",".","HTTP_200_OK",")","else",":","return","Response","(","\"Invalid URL\"",",","status","=","response_status",".","HTTP_404_NOT_FOUND",")","elif","request",".","method","==","\"DELETE\"",":","if","user_id","and","id",":","Demo",".","objects",".","get","(","id","=","id",",","user_id","=","user_id",")",".","delete","(",")","return","Response","(","{","\"removed\"",":","True","}",",","status","=","response_status",".","HTTP_200_OK",")","else",":","return","Response","(","\"Invalid URL\"",",","status","=","response_status",".","HTTP_404_NOT_FOUND",")","return","Response","(","\"Invalid URL\"",",","status","=","response_status",".","HTTP_404_NOT_FOUND",")"],"url":"https:\/\/github.com\/Cloud-CV\/Origami\/blob\/8046898c1afdcc0d32ac3c4a0909f63e2133c3a0\/api\/views.py#L292-L389"}
{"nwo":"Cloud-CV\/Origami","sha":"8046898c1afdcc0d32ac3c4a0909f63e2133c3a0","path":"api\/views.py","language":"python","identifier":"get_permalink","parameters":"(request, shorturl)","argument_list":"","return_statement":"return Response([serialize.data], status=response_status.HTTP_200_OK)","docstring":"Returns the permalink corresponding to the given shorturl.","docstring_summary":"Returns the permalink corresponding to the given shorturl.","docstring_tokens":["Returns","the","permalink","corresponding","to","the","given","shorturl","."],"function":"def get_permalink(request, shorturl):\n \"\"\"Returns the permalink corresponding to the given shorturl.\"\"\"\n try:\n permalink = Permalink.objects.get(short_relative_url='\/p\/' + shorturl)\n\n except Exception:\n return Response({\"text\": \"Not Found\"})\n\n permalink.short_relative_url = permalink.short_relative_url.split('\/')[-1]\n serialize = PermalinkSerializer(permalink)\n return Response([serialize.data], status=response_status.HTTP_200_OK)","function_tokens":["def","get_permalink","(","request",",","shorturl",")",":","try",":","permalink","=","Permalink",".","objects",".","get","(","short_relative_url","=","'\/p\/'","+","shorturl",")","except","Exception",":","return","Response","(","{","\"text\"",":","\"Not Found\"","}",")","permalink",".","short_relative_url","=","permalink",".","short_relative_url",".","split","(","'\/'",")","[","-","1","]","serialize","=","PermalinkSerializer","(","permalink",")","return","Response","(","[","serialize",".","data","]",",","status","=","response_status",".","HTTP_200_OK",")"],"url":"https:\/\/github.com\/Cloud-CV\/Origami\/blob\/8046898c1afdcc0d32ac3c4a0909f63e2133c3a0\/api\/views.py#L393-L403"}
{"nwo":"Cloud-CV\/Origami","sha":"8046898c1afdcc0d32ac3c4a0909f63e2133c3a0","path":"api\/views.py","language":"python","identifier":"custom_permalink_controller","parameters":"(request, user_id, project_id)","argument_list":"","return_statement":"return Response(\"Invalid URL\", status=response_status.HTTP_404_NOT_FOUND)","docstring":"Gets properties of, adds, updates, or deletes a Permalink\n object given a GET, POST, PUT, or DELETE request respectively.\n\n A GET request returns the Permalink corresponding to the\n given user_id and project_id, if they are both specified.\n A GET request returns all Permalink objects otherwise.\n\n Keyword arguments:\n user_id (str): The id of the user\n project_id (str): The id of the project","docstring_summary":"Gets properties of, adds, updates, or deletes a Permalink\n object given a GET, POST, PUT, or DELETE request respectively.","docstring_tokens":["Gets","properties","of","adds","updates","or","deletes","a","Permalink","object","given","a","GET","POST","PUT","or","DELETE","request","respectively","."],"function":"def custom_permalink_controller(request, user_id, project_id):\n \"\"\"\n Gets properties of, adds, updates, or deletes a Permalink\n object given a GET, POST, PUT, or DELETE request respectively.\n\n A GET request returns the Permalink corresponding to the\n given user_id and project_id, if they are both specified.\n A GET request returns all Permalink objects otherwise.\n\n Keyword arguments:\n user_id (str): The id of the user\n project_id (str): The id of the project\n \"\"\"\n if request.method == \"GET\":\n if user_id and project_id:\n try:\n permalink = Permalink.objects.get(project_id=project_id, user_id=user_id)\n\n except Exception:\n return Response({\"text\": \"Not Found\"})\n serialize = PermalinkSerializer(permalink)\n return Response(serialize.data, status=response_status.HTTP_200_OK)\n else:\n try:\n permalinks = Permalink.objects.all()\n\n except Exception:\n return Response({\"text\": \"Not Found\"})\n serialize = PermalinkSerializer(permalinks, many=True)\n return Response(serialize.data, status=response_status.HTTP_200_OK)\n\n elif request.method == \"POST\":\n body = request.data\n short_relative_url = body[\"short_relative_url\"]\n full_relative_url = body[\"full_relative_url\"]\n project_id = body[\"project_id\"]\n user_id = body[\"user_id\"]\n permalink = Permalink.objects.create(\n short_relative_url=short_relative_url,\n full_relative_url=full_relative_url,\n project_id=project_id,\n user_id=user_id)\n serialize = PermalinkSerializer(permalink)\n return Response(serialize.data, status=response_status.HTTP_201_CREATED)\n\n elif request.method == \"PUT\":\n if user_id and project_id:\n body = request.data\n perm = Permalink.objects.get(user_id=user_id, project_id=project_id)\n perm.short_relative_url = body[\"short_relative_url\"]\n perm.full_relative_url = body[\"full_relative_url\"]\n perm.save()\n serialize = PermalinkSerializer(perm)\n return Response(serialize.data, status=response_status.HTTP_200_OK)\n else:\n return Response(\"Invalid URL\", status=response_status.HTTP_404_NOT_FOUND)\n\n elif request.method == \"DELETE\":\n if user_id and project_id:\n Permalink.objects.get(project_id=project_id, user_id=user_id).delete()\n return Response({\"removed\": True}, status=response_status.HTTP_200_OK)\n else:\n return Response(\"Invalid URL\", status=response_status.HTTP_404_NOT_FOUND)\n return Response(\"Invalid URL\", status=response_status.HTTP_404_NOT_FOUND)","function_tokens":["def","custom_permalink_controller","(","request",",","user_id",",","project_id",")",":","if","request",".","method","==","\"GET\"",":","if","user_id","and","project_id",":","try",":","permalink","=","Permalink",".","objects",".","get","(","project_id","=","project_id",",","user_id","=","user_id",")","except","Exception",":","return","Response","(","{","\"text\"",":","\"Not Found\"","}",")","serialize","=","PermalinkSerializer","(","permalink",")","return","Response","(","serialize",".","data",",","status","=","response_status",".","HTTP_200_OK",")","else",":","try",":","permalinks","=","Permalink",".","objects",".","all","(",")","except","Exception",":","return","Response","(","{","\"text\"",":","\"Not Found\"","}",")","serialize","=","PermalinkSerializer","(","permalinks",",","many","=","True",")","return","Response","(","serialize",".","data",",","status","=","response_status",".","HTTP_200_OK",")","elif","request",".","method","==","\"POST\"",":","body","=","request",".","data","short_relative_url","=","body","[","\"short_relative_url\"","]","full_relative_url","=","body","[","\"full_relative_url\"","]","project_id","=","body","[","\"project_id\"","]","user_id","=","body","[","\"user_id\"","]","permalink","=","Permalink",".","objects",".","create","(","short_relative_url","=","short_relative_url",",","full_relative_url","=","full_relative_url",",","project_id","=","project_id",",","user_id","=","user_id",")","serialize","=","PermalinkSerializer","(","permalink",")","return","Response","(","serialize",".","data",",","status","=","response_status",".","HTTP_201_CREATED",")","elif","request",".","method","==","\"PUT\"",":","if","user_id","and","project_id",":","body","=","request",".","data","perm","=","Permalink",".","objects",".","get","(","user_id","=","user_id",",","project_id","=","project_id",")","perm",".","short_relative_url","=","body","[","\"short_relative_url\"","]","perm",".","full_relative_url","=","body","[","\"full_relative_url\"","]","perm",".","save","(",")","serialize","=","PermalinkSerializer","(","perm",")","return","Response","(","serialize",".","data",",","status","=","response_status",".","HTTP_200_OK",")","else",":","return","Response","(","\"Invalid URL\"",",","status","=","response_status",".","HTTP_404_NOT_FOUND",")","elif","request",".","method","==","\"DELETE\"",":","if","user_id","and","project_id",":","Permalink",".","objects",".","get","(","project_id","=","project_id",",","user_id","=","user_id",")",".","delete","(",")","return","Response","(","{","\"removed\"",":","True","}",",","status","=","response_status",".","HTTP_200_OK",")","else",":","return","Response","(","\"Invalid URL\"",",","status","=","response_status",".","HTTP_404_NOT_FOUND",")","return","Response","(","\"Invalid URL\"",",","status","=","response_status",".","HTTP_404_NOT_FOUND",")"],"url":"https:\/\/github.com\/Cloud-CV\/Origami\/blob\/8046898c1afdcc0d32ac3c4a0909f63e2133c3a0\/api\/views.py#L407-L470"}
{"nwo":"Cloud-CV\/Origami","sha":"8046898c1afdcc0d32ac3c4a0909f63e2133c3a0","path":"api\/views.py","language":"python","identifier":"root_settings","parameters":"(request)","argument_list":"","return_statement":"return Response(serialize.data, status=response_status.HTTP_200_OK)","docstring":"A GET request returns the RootSettings object.\n A POST request creates the RootSettings object if there is\n no existent RootSettings object, and updates the existing\n object otherwise.\n\n If a RootSettings object is created, a SocialApp object is\n created as well.","docstring_summary":"A GET request returns the RootSettings object.\n A POST request creates the RootSettings object if there is\n no existent RootSettings object, and updates the existing\n object otherwise.","docstring_tokens":["A","GET","request","returns","the","RootSettings","object",".","A","POST","request","creates","the","RootSettings","object","if","there","is","no","existent","RootSettings","object","and","updates","the","existing","object","otherwise","."],"function":"def root_settings(request):\n \"\"\"\n A GET request returns the RootSettings object.\n A POST request creates the RootSettings object if there is\n no existent RootSettings object, and updates the existing\n object otherwise.\n\n If a RootSettings object is created, a SocialApp object is\n created as well.\n \"\"\"\n body = request.data\n root = RootSettings.objects.all().first()\n app = SocialApp.objects.all().first()\n if request.method == \"POST\":\n if root and app:\n root.root_user_github_login_id = body[\"root_user_github_login_id\"]\n root.root_user_github_login_name = \\\n body[\"root_user_github_login_name\"]\n root.client_id = body[\"client_id\"]\n root.client_secret = body[\"client_secret\"]\n root.is_cloudcv = body[\"is_cloudcv\"]\n root.allow_new_logins = body[\"allow_new_logins\"]\n root.app_ip = body[\"app_ip\"]\n root.port = body[\"port\"]\n root.save()\n app.client_id = body[\"client_id\"]\n app.secret = body[\"client_secret\"]\n app.save()\n else:\n root = RootSettings.objects.create(\n root_user_github_login_id=body[\"root_user_github_login_id\"],\n root_user_github_login_name=body[\"root_user_github_login_name\"],\n client_id=body[\"client_id\"],\n client_secret=body[\"client_secret\"],\n is_cloudcv=body[\"is_cloudcv\"],\n allow_new_logins=body[\"allow_new_logins\"],\n app_ip=body[\"app_ip\"],\n port=body[\"port\"])\n app = SocialApp.objects.create(\n provider=u'github',\n name=str(datetime.datetime.now().isoformat()),\n client_id=body[\"client_id\"],\n secret=body[\"client_secret\"])\n site = Site.objects.get(id=1)\n app.sites.add(site)\n app.save()\n serialize = RootSettingsSerializer(root)\n return Response(serialize.data, status=response_status.HTTP_200_OK)","function_tokens":["def","root_settings","(","request",")",":","body","=","request",".","data","root","=","RootSettings",".","objects",".","all","(",")",".","first","(",")","app","=","SocialApp",".","objects",".","all","(",")",".","first","(",")","if","request",".","method","==","\"POST\"",":","if","root","and","app",":","root",".","root_user_github_login_id","=","body","[","\"root_user_github_login_id\"","]","root",".","root_user_github_login_name","=","body","[","\"root_user_github_login_name\"","]","root",".","client_id","=","body","[","\"client_id\"","]","root",".","client_secret","=","body","[","\"client_secret\"","]","root",".","is_cloudcv","=","body","[","\"is_cloudcv\"","]","root",".","allow_new_logins","=","body","[","\"allow_new_logins\"","]","root",".","app_ip","=","body","[","\"app_ip\"","]","root",".","port","=","body","[","\"port\"","]","root",".","save","(",")","app",".","client_id","=","body","[","\"client_id\"","]","app",".","secret","=","body","[","\"client_secret\"","]","app",".","save","(",")","else",":","root","=","RootSettings",".","objects",".","create","(","root_user_github_login_id","=","body","[","\"root_user_github_login_id\"","]",",","root_user_github_login_name","=","body","[","\"root_user_github_login_name\"","]",",","client_id","=","body","[","\"client_id\"","]",",","client_secret","=","body","[","\"client_secret\"","]",",","is_cloudcv","=","body","[","\"is_cloudcv\"","]",",","allow_new_logins","=","body","[","\"allow_new_logins\"","]",",","app_ip","=","body","[","\"app_ip\"","]",",","port","=","body","[","\"port\"","]",")","app","=","SocialApp",".","objects",".","create","(","provider","=","u'github'",",","name","=","str","(","datetime",".","datetime",".","now","(",")",".","isoformat","(",")",")",",","client_id","=","body","[","\"client_id\"","]",",","secret","=","body","[","\"client_secret\"","]",")","site","=","Site",".","objects",".","get","(","id","=","1",")","app",".","sites",".","add","(","site",")","app",".","save","(",")","serialize","=","RootSettingsSerializer","(","root",")","return","Response","(","serialize",".","data",",","status","=","response_status",".","HTTP_200_OK",")"],"url":"https:\/\/github.com\/Cloud-CV\/Origami\/blob\/8046898c1afdcc0d32ac3c4a0909f63e2133c3a0\/api\/views.py#L474-L521"}
{"nwo":"Cloud-CV\/Origami","sha":"8046898c1afdcc0d32ac3c4a0909f63e2133c3a0","path":"api\/views.py","language":"python","identifier":"upload_sample_input","parameters":"(request)","argument_list":"","return_statement":"return Response(serialize.data, status=response_status.HTTP_200_OK)","docstring":"Creates a sample input. Only image input is supported currently.\n\n The data passed into the POST request needs to contain:\n demo_id (str): The demo that the sample input should belong to.\n sample-image-* (file): A value with its key having 'sample-image'\n as a prefix, containing the image file.","docstring_summary":"Creates a sample input. Only image input is supported currently.","docstring_tokens":["Creates","a","sample","input",".","Only","image","input","is","supported","currently","."],"function":"def upload_sample_input(request):\n \"\"\"\n Creates a sample input. Only image input is supported currently.\n\n The data passed into the POST request needs to contain:\n demo_id (str): The demo that the sample input should belong to.\n sample-image-* (file): A value with its key having 'sample-image'\n as a prefix, containing the image file.\n \"\"\"\n data = request.data\n demo_id = data[\"demo_id\"]\n demo = Demo.objects.get(id=demo_id)\n for key, value in data.items():\n if key.startswith(\"sample-image\"):\n img = request.FILES[key]\n absolute_path = default_storage.save(settings.MEDIA_ROOT, ContentFile(img.read()))\n relative_path = '\/media\/' + absolute_path.split('media\/')[-1]\n sample_input = SampleInput.objects.create(demo=demo, type_of_input=3, value=relative_path)\n serialize = SampleInputSerializer(sample_input)\n if (\"test\" in sys.argv):\n os.remove(absolute_path)\n sample_inputs = SampleInput.objects.filter(demo=demo)\n serialize = SampleInputSerializer(sample_inputs, many=True)\n return Response(serialize.data, status=response_status.HTTP_200_OK)","function_tokens":["def","upload_sample_input","(","request",")",":","data","=","request",".","data","demo_id","=","data","[","\"demo_id\"","]","demo","=","Demo",".","objects",".","get","(","id","=","demo_id",")","for","key",",","value","in","data",".","items","(",")",":","if","key",".","startswith","(","\"sample-image\"",")",":","img","=","request",".","FILES","[","key","]","absolute_path","=","default_storage",".","save","(","settings",".","MEDIA_ROOT",",","ContentFile","(","img",".","read","(",")",")",")","relative_path","=","'\/media\/'","+","absolute_path",".","split","(","'media\/'",")","[","-","1","]","sample_input","=","SampleInput",".","objects",".","create","(","demo","=","demo",",","type_of_input","=","3",",","value","=","relative_path",")","serialize","=","SampleInputSerializer","(","sample_input",")","if","(","\"test\"","in","sys",".","argv",")",":","os",".","remove","(","absolute_path",")","sample_inputs","=","SampleInput",".","objects",".","filter","(","demo","=","demo",")","serialize","=","SampleInputSerializer","(","sample_inputs",",","many","=","True",")","return","Response","(","serialize",".","data",",","status","=","response_status",".","HTTP_200_OK",")"],"url":"https:\/\/github.com\/Cloud-CV\/Origami\/blob\/8046898c1afdcc0d32ac3c4a0909f63e2133c3a0\/api\/views.py#L525-L548"}