def add(): teams = Team.query.all() if not teams: return render_template("no_teams.html") form = ScoreForm() form.team_id.choices = [(t.id, t.number) for t in sortTeamsWithPlaceholder(teams)] # don't allow playoff round options during qualifying, or qualifying during playoffs if any(team.highest_round_reached > 3 for team in teams): form.round_number.choices = [(-1, 'Select'), (1, '1'), (2, '2'), (3, '3'), (4, 'Quarterfinals'), (5, 'Semifinals'), (6, 'Finals')] else: form.round_number.choices = [(-1, 'Select'), (1, '1'), (2, '2'), (3, '3')] # Gather and preset the team ID and round number fields if provided in URL preselected_team = request.args.get('team_id', default=None, type=int) preselected_round = request.args.get('round', default=None, type=int) if preselected_team is not None and request.method == 'GET': form.team_id.data = preselected_team if preselected_round is not None and request.method == 'GET': form.round_number.data = preselected_round repeat = request.args.get('repeat', default=False, type=bool) if request.method == 'POST' and request.form['end'] == 'reset': return redirect(url_for(".add", round=preselected_round, repeat=True)) elif request.method == 'POST' and request.form[ 'end'] == 'submit' and form.validate_on_submit(): score = RobotScore(team=form.team_id.data, round_number=form.round_number.data) populate_score(score, form) db.session.add(score) db.session.commit() if repeat: flash( 'Added score for %s round %s' % (score.team.number, score.round_number), 'success') return redirect( url_for(".add", round=preselected_round, repeat=True)) else: if form.round_number.data <= 3: return redirect(url_for("review")) else: return redirect(url_for(".playoffs")) elif request.method == 'POST': flash('Failed validation', 'danger alert-auto-dismiss') return render_template("scoring/score_form.html", form=form, id=None, repeat=repeat)
def add(): teams = Team.query.all() if not teams: return render_template("no_teams.html") form = ScoreForm() form.team_id.choices = [(t.id, t.number) for t in sortTeamsWithPlaceholder(teams)] # don't allow playoff round options during qualifying, or qualifying during playoffs if any(team.highest_round_reached > 3 for team in teams): form.round_number.choices = [(-1, 'Select'), (1, '1'), (2, '2'), (3, '3'), (4, 'Quarterfinals'), (5, 'Semifinals'), (6, 'Finals')] else: form.round_number.choices = [(-1, 'Select'), (1, '1'), (2, '2'), (3, '3')] # Gather and preset the team ID and round number fields if provided in URL preselected_team = request.args.get('team_id', default=None, type=int) preselected_round = request.args.get('round', default=None, type=int) if preselected_team is not None and request.method == 'GET': form.team_id.data = preselected_team if preselected_round is not None and request.method == 'GET': form.round_number.data = preselected_round repeat = request.args.get('repeat', default=False, type=bool) if request.method == 'POST' and request.form['end'] == 'reset': return redirect(url_for(".add", round = preselected_round, repeat = True)) elif request.method == 'POST' and request.form['end'] == 'submit' and form.validate_on_submit(): score = RobotScore(team=form.team_id.data, round_number=form.round_number.data) populate_score(score, form) db.session.add(score) db.session.commit() if repeat: flash('Added score for %s round %s' % (score.team.number, score.round_number), 'success') return redirect(url_for(".add", round = preselected_round, repeat = True)) else: if form.round_number.data <= 3: return redirect(url_for("review")) else: return redirect(url_for(".playoffs")) elif request.method == 'POST': flash('Failed validation', 'danger alert-auto-dismiss') return render_template("scoring/score_form.html", form=form, id=None, repeat=repeat)
def game_edit(): #---------Edit score for matches---------# form_s = ScoreForm() game_id = request.form['edit_game'] game = model.session.query(model.Game).get(int(game_id)) if form_s.validate_on_submit(): form_s.game_date = game.game_date form_s.home_team = game.home_team form_s.away_team = game.home_team game.home_score = form_s.home_score.data game.away_score = form_s.away_score.data model.session.add(game) model.session.commit() flash('Your changes have been updated. Select \'Save\' to finalize!') return redirect('calendar')
def game_edit(): #---------Edit score for matches---------# form_s = ScoreForm() game_id= request.form['edit_game'] game= model.session.query(model.Game).get(int(game_id)) if form_s.validate_on_submit(): form_s.game_date = game.game_date form_s.home_team = game.home_team form_s.away_team = game.home_team game.home_score = form_s.home_score.data game.away_score = form_s.away_score.data model.session.add(game) model.session.commit() flash('Your changes have been updated. Select \'Save\' to finalize!') return redirect('schedule')
def edit(score_id): score = RobotScore.query.get(score_id) form = ScoreForm(obj=score) del form.team_id del form.round_number if request.method == 'POST' and form.validate_on_submit(): populate_score(score, form) db.session.commit() if score.round_number <= 3: return redirect(url_for("review")) else: return redirect(url_for(".playoffs")) elif request.method == 'POST': flash('Failed validation', 'danger alert-auto-dismiss') return render_template("scoring/score_form.html", form=form, team_id=score.team.number, round_number=score.round_number, id=score.id)
def edit(score_id): score = RobotScore.query.get(score_id) form = ScoreForm(obj=score) del form.team_id del form.round_number if request.method == 'POST' and form.validate_on_submit(): populate_score(score, form) db.session.commit() if score.round_number <= 3: return redirect(url_for("review")) else: return redirect(url_for(".playoffs")) elif request.method == 'POST': flash('Failed validation', 'danger alert-auto-dismiss') return render_template("scoring/score_form.html", form=form, team_id=score.team.number, round_number=score.round_number, id=score.id)