Пример #1
0
def game_admin():
    game = Game.query.filter_by(name=game_name).first()
    if game is None:
        game = Game(name=game_name,
                    state='stop',
                    announcedData=datetime.utcnow(),
                    gameStarted=False)

        if game.conferenceCode is None:
            chars = 'abcdefghijklnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
            code = ''
            for i in range(15):
                code += random.choice(chars)
            game.conferenceCode = code

        db.session.add(game)
        db.session.commit()
        print("create new Game")

    terminal_history = []
    message_objects = TerminalMessage.query.filter_by(game_id=game.id)
    for message in message_objects:
        terminal_history.append(message.get_json())

    radio_history = []
    message_objects = RadioMessage.query.filter_by(game_id=game.id)
    for message in message_objects:
        radio_history.append(message.get_json())

    return render_template('game_admin.html',
                           time=game.update(datetime.utcnow()),
                           timer_run=game.gameStarted,
                           game_state=game.state,
                           secret_code=game.secretCode,
                           terminal_history=terminal_history,
                           radio_history=radio_history,)