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'))
def test_from_csv(self): games = Games.from_csv(StringIO('\n'.join([ 'slot,name,author,system,blurb,min_players,max_players', '1A,Aargh!,Alice Able,SillyDice,Camelot is a silly place.,,', '1B,Bouncing Babies,Brian May,nWoD,Not a very good idea.,5,7', '2A,Alien Attack,Axl Rose,Cthulhu,Giant robots!,,', '2B,Business,Bob Bobson,SrsBsns,Make some RoI.,,', ]))) self.assertEqual(list(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.'), ])