コード例 #1
0
ファイル: views.py プロジェクト: WarmerHu/subject
def check_answer(req):
    if req.method == "POST" and req.COOKIES.has_key("userid"):
        jsonReq = simplejson.loads(req.body)
        titleId = jsonReq["id"]
        titleAs = jsonReq["answer"]
        usid = req.COOKIES["userid"]
        if titleAs:
            isTitle = Exercise.objects.filter(id=titleId, answer=titleAs)
            if isTitle:
                dao = userDao({"userid": usid})
                dao.update_point_byReq({"method": "+", "points": 1})
                dao.save_update()
                rsp = read_a_title(req=jsonReq["num"], userid=usid)
                return HttpResponse(json.dumps(rsp), content_type="application/json")
        rsp = {"exerciseid": titleId, "userid": usid}
        CDao = collectionDao(rsp)
        if not CDao.select_collection_byExUs():
            CDao.insert_collection()
        return HttpResponse(json.dumps({"tips": get_tips_byId(titleId)}), content_type="application/json")
    return HttpResponse(json.dumps({"tips": "请输入正确的答案"}), content_type="application/json")
コード例 #2
0
ファイル: views.py プロジェクト: WarmerHu/subject
def get_title(req, param):
    if req.COOKIES.has_key("userid"):
        rsp = read_a_title(req=param, userid=req.COOKIES["userid"])
        return HttpResponse(json.dumps(rsp), content_type="application/json")
    return HttpResponse(json.dumps({"tips": "获取失败,请重新登录"}), content_type="application/json")