def unpack_problem_json(request):
data = json.loads(request.body.decode('utf-8'))
if "name" not in data:
return HttpResponseBadRequest("Need to include a reference to 'name' in the json object")
if "courses" not in data:
return HttpResponseBadRequest("Need to include a reference to 'courses' in the json object")
if "tests" not in data:
return HttpResponseBadRequest("Need to include a reference to 'tests' in the json object")
if "solution_code" not in data:
return HttpResponseBadRequest("Need to include a reference to 'solution_code' in the json object")
courses = []
for c in data["courses"]:
course = Course.objects.filter(id=c)
if len(course) != 1:
return HttpResponseBadRequest("No course exists with the ID " + str(c))
courses.append(course[0])
data["courses"] = courses
return data
评论列表
文章目录