def add_games(): """ Render the add-games template on the /add-games route """ search_form = AddGamesSearchForm() populate_games_form(search_form) beautify_games_form(search_form) add_default_values_game_form(search_form) add_game_form = AddGameForm() if search_form.validate_on_submit(): Game.from_title(search_form.title.data) return render_template('add-games.html', form=search_form, stylesheet='add-games', add_game_form=add_game_form) if add_game_form.validate_on_submit(): game_id = Game.max_id() + 1 Game.add_game( game_id, { 'title': add_game_form.title.data, 'publication_year': add_game_form.years.data, 'min_players': int(add_game_form.min_players.data), 'max_players': int(add_game_form.max_players.data), 'min_playtime': int(add_game_form.min_playtime.data), 'image': add_game_form.image.data }) return redirect(url_for('jeux.game', game_id=game_id)) return render_template('add-games.html', stylesheet='add-games', add_game_form=add_game_form)
def populate_games(): with app.open_resource('./testing/data/games.json') as gamedata: games = json.load(gamedata)['games'] for g in games: Game.add_game(teams=g['teams'], court=int(g['court']), time=g['time']) scrs = g['score'].split(' ') Game.update_game(int(g['court']), g['time'], g['winner'], scrs[0], scrs[1])