Exemplo n.º 1
0
def create_game():
    form = CreateGameForm()
    if form.validate_on_submit():
        game = Game(name=form.game_name.data,
                    owner=current_user,
                    blurb=form.blurb.data,
                    player_max=form.get_player_max())
        game.set_password(form.password.data)
        chapter = Chapter(name=form.chapter_name.data, game=game)
        scene = Scene(name=form.chapter_name.data, chapter=chapter)
        db.session.add_all([game, chapter, scene])
        game.ensure_has_current()
        db.session.commit()
        set_currents(int(game.id))
        flash('Congratulations, you created a game called "{}"!'.format(
            game.name))
        return redirect(url_for('game.game', gameid=game.id))
    return render_template('game/create_game.html', form=form)