views.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:ITAP-django 作者: krivers 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号