Example #1
0
def edit_game(game_id):
    if request.method == 'POST':
        game = Game.get_game_by_id(game_id)
        game.location = Location.get_location_by_id(request.form['location'])
        game.stadium = request.form['stadium']
        game.hht_theme = request.form['hht_theme']
        game.save_to_mongo()

    game = Game.get_game_by_id(game_id)
    teams = Team.get_teams()
    locations = Location.get_all_locations()
    stadiums = Game.get_all_stadiums()
    stadiums.sort()

    return render_template("games/edit_game.jinja2",
                           teams=teams,
                           game=game,
                           locations=locations,
                           stadiums=stadiums)
Example #2
0
def create_game():
    if request.method == 'POST':
        new_game = Game(game_num=request.form['game_num'],
                        away_team=request.form['away_team'],
                        home_team=request.form['home_team'],
                        year=request.form['year'],
                        location=Location.get_location_by_id(
                            request.form['location']).json(),
                        stadium=request.form['stadium'],
                        date=datetime.strptime(request.form['date'],
                                               "%m/%d/%Y"))
        new_game.save_to_mongo()
        users = User.get_all_users()
        if new_game.location.city == 'Blacksburg':
            attendance = 'Yes'
        else:
            attendance = 'No'
        for u in users:
            UserGame(user=u.json(),
                     game=new_game._id,
                     attendance=attendance,
                     game_date=None,
                     home_score=0,
                     away_score=0).save_to_mongo()

    years = Year.get_all_years()
    teams = Team.get_teams()
    locations = Location.get_all_locations()
    stadiums = Game.get_all_stadiums()
    stadiums.sort()

    return render_template("games/create_game.jinja2",
                           teams=teams,
                           locations=locations,
                           stadiums=stadiums,
                           years=years)