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 assign_award_winner(award_winner_id): teams = Team.query.all() if not teams: return render_template("no_teams.html") award_winner = AwardWinner.query.get(award_winner_id) form = AwardWinnerForm(obj=award_winner) form.team_id.choices = [(t.id, t.number) for t in sortTeamsWithPlaceholder(teams)] if request.method == 'POST' and form.validate_on_submit(): form.populate_obj(award_winner) db.session.commit() return redirect(url_for(".index")) elif request.method == 'POST': flash('Failed validation', 'danger alert-auto-dismiss') return render_template("awards/award_winner_form.html", form=form, award=award_winner.friendly_award_name)
def add_presentation(): teams = Team.query.all() if not teams: return render_template("no_teams.html") form = PresentationForm() form.team_id.choices = [(t.id, t.number) for t in sortTeamsWithPlaceholder(teams)] # Gather and preset the team ID field if provided in URL preselected_team = request.args.get('team_id', default=None, type=int) if preselected_team is not None: form.team_id.data = preselected_team repeat = request.args.get('repeat', default=False, type=bool) if request.method == 'POST' and request.form['end'] == 'reset': return redirect(url_for(".add_presentation", repeat=True)) elif request.method == 'POST' and request.form[ 'end'] == 'submit' and form.validate_on_submit(): presentation = Presentation() form.populate_obj(presentation) db.session.add(presentation) db.session.commit() if repeat: flash( 'Added presentation score for %s' % (presentation.team.number), 'success') return redirect(url_for(".add_presentation", repeat=True)) else: return redirect(url_for("review")) elif request.method == 'POST': flash('Failed validation', 'danger alert-auto-dismiss') return render_template("judging/presentation_form.html", form=form, id=None, repeat=repeat)