def signups(id): season = Season(id) season.load() form = DivisionForm(request.form) form.user_id.choices = season.get_unasigned_signup_list() if request.method == 'POST' and form.validate_on_submit(): if form.user_id.data: if form.action.data == "assign" and season.add_to_division(form.division.data, form.user_id.data): flash("Division assigned") elif form.action.data == "remove" and season.remove_signups(form.user_id.data): flash("Signups removed") else: flash("Failed") else: flash("No players selected") form.user_id.choices = season.get_unasigned_signup_list() form.season_id.data = id add_user_form = SignupForm() add_user_form.season_id.data = id add_user_form.user_id.choices = season.get_users_for_signup() divisions = get_divisions(season) return render_template("admin/signups.html", season=season, form=form, signups=season.get_signups(), add_user_form=add_user_form)
def remove_from_division(): form = RemoveDivisionForm(request.form) form.division.data = None if form.validate_on_submit(): season = Season(form.season_id.data) if season.remove_from_division(form.user_id.data): flash("Removed from division") return redirect(request.referrer) flash("Failed to remove sign-up's division") return redirect(request.referrer)
def remove_signup(): form = RemoveSignupForm(request.form) if form.validate_on_submit() and Season.remove_signup( form.season_id.data, form.user_id.data): flash("Sign-up removed") else: flash("Failed to remove sign-up") return redirect(request.referrer)
def signup(): query = 'INSERT INTO signups(season_id, user_id) VALUES(?, ?)' values = [Season.get_current_season_id(), current_user.get_id()] try: g.db.execute(query, values) g.db.commit() flash("Signed up") except Exception as e: print e # TODO what was I going to catch? return redirect(request.referrer)
def usnignup(): query = 'DELETE FROM signups WHERE season_id = ? AND user_id = ?' values = (Season.get_current_season_id(), current_user.get_id()) cur = g.db.execute(query, values) if cur.rowcount: g.db.commit() flash("Signup removed") else: g.db.rollback() flash("Failed to remove your signup") return redirect(request.referrer)
def season_link(): query = """ SELECT id FROM seasons ORDER BY id DESC """ cur = g.db.execute(query) seasons = (x[0] for x in cur.fetchall()) links = [] for season_id in seasons: links = links + [(url_for('season', id=season_id), 'season', 'Season %i'%season_id)] return ('/', 'season', "Season %i" % Season.get_current_season_id())
def signups(): season_id = Season.get_current_season_id() user_id = current_user.get_id() signups = get_signups(season_id) query = """ SELECT COUNT(*) as count FROM signups WHERE season_id = ? AND user_id = ? """ signedup = query_db(query, [season_id, user_id], True)['count'] return render_template('signups.html', signups=signups, signedup=signedup, divisions=get_divisions(season_id))
def match_link(): if current_user.is_authenticated(): season_id = Season.get_current_season_id() query = """ SELECT COUNT(*) as count FROM matches LEFT JOIN match_players ON match_id = matches.id WHERE season_id = ? AND user_id = ? """ result = query_db(query, (season_id, current_user.get_id()), True) if result['count']: return ('matches/my', 'matches', "Matches (%i)" % result['count']) return ('/matches', 'matches', "Matches")
def map_pool(id): season = Season(id) season.load() form = MapPoolForm(request.form) form.map_id.choices = season.get_maps_not_in_pool() if request.method == 'POST' and form.validate_on_submit(): query = """ INSERT INTO season_maps(season_id, map_id) VALUES(?, ?) """ values = (form.season_id.data, form.map_id.data) cur = g.db.execute(query, values) if cur.rowcount: flash("Map added to the pool") g.db.commit() else: flash("Failed to add map") g.db.rollback() form.season_id.data = id form.map_id.choices = season.get_maps_not_in_pool() return render_template("admin/map_pool.html", form=form, season=season)
def matches(id): form = GenerateMatchesForm(request.form) if request.method == 'POST' and form.validate_on_submit(): season = Season(form.season_id.data) maps = form.maps.data interval = form.interval.data start = form.first_default_time.data for division in season.get_division_numbers(): if season.create_matches(division, maps, start, interval): flash("Generated matches for division " + str(division)) else: flash("Failed to generate matches for division " + str(division)) season = Season(id) season.load() form.season_id.data = id divisions = get_divisions(season) return render_template("admin/matches.html", season=season, form=form, matches=season.get_matches())
def league(): return redirect(url_for('.signups', id=Season.get_current_season_id()))