Ejemplo n.º 1
0
    def test_from_csv(self):
        games = make_games(['1A', '1B'])
        players = make_players([
            (1, 'GM1A', None, {'1A': 'G'}),
            (1, 'GM1B', None, {'1B': 'G'}),
            (5, 'P1A', None, {'1A': 'P'}),
            (5, 'P1B', None, {'1B': 'P'}),
        ])

        game_tables = GameTables.from_csv(
            games, players, StringIO('\n'.join([
                'slot,gm,players',
                '1A,GM1A 0,P1A 0,P1A 1,P1A 2,P1A 3,P1A 4',
                '1B,GM1B 0,P1B 0,P1B 1,P1B 2,P1B 3,P1B 4',
            ])))

        self.assertEqual(
            list(game_tables.all_tables()),
            list(GameTables(games, players, {
                '1A': [GameTable(
                    games['1A'], players.get_player('GM1A 0'),
                    [players.get_player('P1A %s' % (i,)) for i in xrange(5)])],
                '1B': [GameTable(
                    games['1B'], players.get_player('GM1B 0'),
                    [players.get_player('P1B %s' % (i,)) for i in xrange(5)])],
            }).all_tables()))
Ejemplo n.º 2
0
def tables_upload():
    games = db.get_games()
    players = db.get_players()
    game_tables = GameTables.from_csv(
        games, players, request.files['tables.csv'])
    db.set_all_game_tables(game_tables)
    flash("Tables imported.")
    return redirect(url_for('tables'))