コード例 #1
0
async def ContestMark(request):
    try:
        judgeEmail = request.raw_args['judgeEmail']
        contest = json.loads(request.raw_args['contest'])
        mark = request.raw_args['mark']
        data = db.Contest.find_one(
            {'info.contestName': contest['info']['contestName']},
            {'_id': False})
        if 'mark' in data:
            data['mark'][judgeEmail] = json.loads(mark)
        else:
            data['mark'] = {judgeEmail: json.loads(mark)}
        db.Contest.update({'info.contestName': contest['info']['contestName']},
                          data,
                          upsert=False)
        final = calFinal(contest['info']['contestName'])
        if final != {}:
            data['final'] = final
            db.Contest.update(
                {'info.contestName': contest['info']['contestName']},
                data,
                upsert=False)
        judgeData = db.User.find_one({'email': judgeEmail}, {'_id': False})
        del judgeData['cache']
        db.User.update({'email': judgeEmail}, judgeData, upsert=False)
        return jsonRes({'status': 'success'})
    except Exception as e:
        traceback.print_exc()
        return jsonRes({'status': 'failed', 'detail': e})
コード例 #2
0
async def ContestInfo(request):
    try:
        data = db.Contest.find_one(
            {'info.contestName': request.raw_args['selected']}, {'_id': False})
        return jsonRes({'status': 'success', 'data': data})
    except Exception as e:
        return jsonRes({'status': 'failed', 'detail': e})
コード例 #3
0
async def JudgeInfo(request):
    try:
        data = db.User.find_one({'email': request.raw_args['selected']},
                                {'_id': False})
        return jsonRes({'status': 'success', 'data': data})
    except Exception as e:
        return jsonRes({'status': 'failed', 'detail': e})
コード例 #4
0
async def ContestCreate(request):
    try:
        jsonObj = request.raw_args
        for (key, val) in jsonObj.items():
            jsonObj[key] = json.loads(val)
        db.Contest.insert_one(jsonObj)
        for each in jsonObj['judge']['judges']:
            userData = db.User.find_one({'email': each['email']}) or each

            if userData != each:  # Old User
                userData['contests'][jsonObj['info']
                                     ['contestName']] = each['term']
            else:  # New User
                global user
                #userData['passwd'] = user.randomPasswd()  <-- Random passwd
                userData['passwd'] = user.hashPasswd(
                    each['email'])  # <-- Temporary password same as email
                userData['contests'] = {
                    jsonObj['info']['contestName']: each['term']
                }
                del userData['term']
            db.User.update({'email': each['email']}, userData, upsert=True)
        return jsonRes({'status': 'success'})
    except Exception as e:
        traceback.print_exc()
        return jsonRes({'status': 'failed', 'detail': e})
コード例 #5
0
async def ContestList(request):
    try:
        res = {}
        res['contest-lists'] = db.Contest.find(projection={
            'info': True,
            '_id': False
        })
        return jsonRes({'status': 'success', 'data': res})
    except Exception as e:
        return jsonRes({'status': 'failed', 'detail': e})
コード例 #6
0
async def Login(request):
    try:
        email = request.raw_args['account']
        hashPasswd = user.hashPasswd(request.raw_args['passwd'])
        data = db.User.find_one({
            'email': email,
            'passwd': hashPasswd
        },
                                projection={'_id': False})
        del data['passwd']
        return jsonRes({'status': 'success', 'data': data})
    except Exception as e:
        return jsonRes({'status': 'failed', 'detail': e})
コード例 #7
0
async def JudgeCache(request):
    try:
        judgeEmail = request.raw_args['judgeEmail']
        userData = db.User.find_one({'email': judgeEmail}, {'_id': False})
        insertData = request.raw_args
        del insertData['judgeEmail']
        insertData['contest'] = json.loads(insertData['contest'])
        insertData['mark'] = json.loads(insertData['mark'])
        userData['cache'] = insertData
        db.User.update({'email': judgeEmail}, userData, upsert=False)
        return jsonRes({'status': 'success'})
    except Exception as e:
        traceback.print_exc()
        return jsonRes({'status': 'failed', 'detail': e})
コード例 #8
0
async def ContestCheck(request):
    try:
        data = db.Contest.find(request.raw_args, projection={'_id': False})
        return jsonRes({'status': 'success', 'data': data})
    except Exception as e:
        return jsonRes({'status': 'failed', 'detail': e})
コード例 #9
0
async def index(request):
    return jsonRes({'hello': 'world'})