示例#1
0
def a():
    teams = TeamModel.objects(teamName__ne='empty')
    for booth in BoothModel.objects():
        t = choice(teams)
        booth.own_team = t
        booth.save()
    return '', 200
示例#2
0
    def get(self):
        ret = []
        user = AdminUserModel.objects(userId=get_jwt_identity()).first()

        total_ = len(BoothModel.objects(
            game=user['game']))  # user의 현재 게임 내에 있는 총 부스의 개수
        for team in TeamModel.objects(game=user['game']):
            # temp 는 해당 team 이 점령한 부스의 개수를 지칭
            temp = len(BoothModel.objects(ownTeam=team))
            ret.append({
                "teamId": team.teamColor,
                "ownCount": temp,
                "percent": temp / total_ * 100
            })

        return ret, 201  # for 문이 끝나고 ret 반환
示例#3
0
 def _create_booth(self):
     default_team = TeamModel.objects(team_id=0).first()
     for i in range(5):
         BoothModel(
             game=self.test_game,
             booth_name=f'booth{i}',
             own_team=default_team,
         ).save()
示例#4
0
    def get(self):
        user = AdminUserModel.objects(userId=get_jwt_identity()).first()
        game = user.game
        booth_list = BoothModel.objects(game=game)

        return uni_json({
            'booths': [{
                'boothName': booth.boothName,
                'ownTeam': booth.ownTeam.teamColor
            } for booth in booth_list]
        })
示例#5
0
 def get(self):
     user = AdminUserModel.objects(userId=get_jwt_identity()).first()
     return uni_json([
         {
             "bootName":
             booth.boothName,
             "ownTeam":
             TeamModel.objects(game=user.game,
                               teamId=booth.ownTeam.teamId).first().teamId
             # "ownTeam": booth.ownTeam.id
         } for booth in BoothModel.objects(game=user['game'])
     ])
示例#6
0
    def post(self):
        edits_ = request.json['edits']  # boothName
        user = AdminUserModel.objects(userId=get_jwt_identity()).first()
        game = user['game'].id

        if not user:
            abort(401)
        else:
            for array in edits_:
                BoothModel(game=game,
                           boothName=array['boothName'],
                           ownTeam=TeamModel.objects(teamId=0).first()).save()

            return {
                "status": "Successfully inserted problem information."
            }, 201
示例#7
0
    def get(self):
        factory = qrcode.image.svg.SvgImage
        game_ = AdminUserModel.objects(userId=get_jwt_identity()).first().game

        directory = 'static/qr/' + str(game_.gameKey)
        if os.path.exists(directory):
            shutil.rmtree(directory)
        os.makedirs(directory)
        directory += '\\'

        zip = zipfile.ZipFile(directory + 'qr.zip', 'w')
        for booth in BoothModel.objects(game=game_):
            file_name = directory + booth.boothName + '.svg'
            qrcode.make(booth.boothName, image_factory=factory).save(file_name)

            zip.write(file_name,
                      booth.boothName + '.svg',
                      compress_type=zipfile.ZIP_DEFLATED)
        zip.close()

        return send_file(directory + 'qr.zip', mimetype='application/zip')
示例#8
0
    def post(self, boothName: str) -> Response:

        self._check_time(g.game)

        payload: dict = request.json

        problem: ProblemModel = ProblemModel.objects(problem_id=payload['problemId']).first()
        booth: BoothModel = BoothModel.objects(booth_name=boothName).first()
        if not all((problem, booth)):
            return Response('', 204)

        if booth.next_capture_time > datetime.now():
            abort(408)

        if payload['answer'] != problem.answer:
            return Response('', 205)

        booth.own_team = g.user.team
        booth.next_capture_time = datetime.now() + timedelta(minutes=1)
        booth.save()

        return Response('', 201)
示例#9
0
    def get(self, boothName: str) -> Response:

        self._check_time(g.game)

        booth: BoothModel = BoothModel.objects(booth_name=boothName).first()
        if not booth:
            return Response('', 204)

        if booth.own_team == g.user.team:
            return Response('', 205)

        if booth.next_capture_time > datetime.now():
            abort(408)

        problem: ProblemModel = choice(ProblemModel.objects())

        response = {'boothName': boothName,
                    'problemId': problem.problem_id,
                    'content': problem.content,
                    'choices': problem.choices}

        return jsonify(response)
示例#10
0
    def get(self) -> Response:
        if not g.user:
            return abort(403)

        default_team: TeamModel = TeamModel.objects(team_id=0,
                                                    game=g.game).first()
        map_: dict = {
            'map': {},
            'myTeam': g.user.team.team_id,
            'myTeamColor': g.user.team.team_color
        }
        booths: List[BoothModel] = BoothModel.objects(game=g.game)

        for booth in booths:
            if booth.own_team == default_team:
                map_['map'][booth.booth_name] = -1
            elif booth.own_team == g.user.team:
                map_['map'][booth.booth_name] = 1
            else:
                map_['map'][booth.booth_name] = 0

        return jsonify(map_)
    def test_success_solve_post(self):
        rv = solve_post_request(self)
        booth = BoothModel.objects(booth_name='booth0').first()

        self.assertEqual(booth.own_team, self.test_user.team)
        return rv