예제 #1
0
파일: web.py 프로젝트: jerith/table-minion
def games_upload():
    f = request.files['games_file']
    if f.filename.endswith('.csv'):
        games = Games.from_csv(f)
    else:
        games = Games.from_xls(f.read())
    db.import_games(games, delete=True)
    flash("Games imported.")
    return redirect(url_for('games'))
예제 #2
0
파일: db.py 프로젝트: jerith/table-minion
def get_games():
    query = '''
    SELECT slot, name, author, system, blurb, min_players, max_players
    FROM games;
    '''
    rows = query_db(query)
    return Games.from_dicts([dict(zip(row.keys(), row)) for row in rows])
예제 #3
0
 def test_from_xls(self):
     xls_file = open(os.path.join(os.path.dirname(__file__), 'games.xls'))
     games = Games.from_xls(xls_file.read())
     self.assertEqual(list(games), [
         Game('1A', 'Game 1A', 'Author 1A', 'System 1A', 'Blurb 1A', 4, 6),
         Game('1B', 'Game 1B', 'Author 1B', 'System 1B', 'Blurb 1B', 5, 5),
     ])
예제 #4
0
 def test_to_csv(self):
     games = Games([
         Game('1A', 'Aargh!', 'Alice Able', 'SillyDice',
              'Camelot is a silly place.', 4, 6),
         Game('1B', 'Bouncing Babies', 'Brian May', 'nWoD',
              'Not a very good idea.', 5, 7),
         Game('2A', 'Alien Attack', 'Axl Rose', 'Cthulhu', 'Giant robots!'),
         Game('2B', 'Business', 'Bob Bobson', 'SrsBsns', 'Make some RoI.'),
     ])
     games_csv = StringIO()
     games.to_csv(games_csv)
     self.assertEqual(
         games_csv.getvalue(), '\r\n'.join([
             'slot,name,author,system,blurb,min_players,max_players',
             '1A,Aargh!,Alice Able,SillyDice,Camelot is a silly place.,4,6',
             '1B,Bouncing Babies,Brian May,nWoD,Not a very good idea.,5,7',
             '2A,Alien Attack,Axl Rose,Cthulhu,Giant robots!,4,6',
             '2B,Business,Bob Bobson,SrsBsns,Make some RoI.,4,6',
             '',
         ]))