@@ 3,7 3,7 @@ from flask import Blueprint, render_template, redirect, url_for, flash, abort, r
from flask_login import login_required, current_user
from fllscoring.models import Tournaments, Team
-from fllscoring.setup.forms import NewTournamentForm, NewTeamForm
+from fllscoring.setup.forms import NewTournamentForm, NewTeamForm, EditTeamForm
from fllscoring import db
bp = Blueprint('setup', __name__, url_prefix="/setup")
@@ 67,4 67,41 @@ def new_team(tournament_id):
db.session.add(team)
db.session.commit()
return redirect(url_for("setup.manage_tournament", id=tournament_id))
- return render_template("setup/new_team.html", form=form, title=f"New Team for tournament {tournament_id}")>
\ No newline at end of file
+ return render_template("setup/new_team.html", form=form, title=f"New Team for tournament {tournament_id}")
+
+@bp.route("/edit_team/<int:tournament_id>/<int:team_id>", methods=["GET", "POST"])
+@login_required
+def edit_team(tournament_id, team_id):
+ team = Team.query.filter_by(id=team_id).first()
+ if team is None:
+ abort(404)
+
+ if request.method == "POST":
+ form = EditTeamForm(request.form, obj=team)
+ if form.validate():
+ form.populate_obj(team)
+ db.session.add(team)
+ db.session.commit()
+ return redirect(url_for('setup.manage_tournament', id=team.tournament))
+ else:
+ form = EditTeamForm(obj=team)
+
+ return render_template("setup/edit_team.html", form=form, title=f"Edit team {team.team_name}", team=team)
+
+@bp.route("/delete_team/<int:tournament_id>/<int:team_id>", methods=["GET", "POST"])
+@login_required
+def delete_team(tournament_id, team_id):
+ team = Team.query.filter_by(id=team_id).first()
+ tournament = Tournaments.query.filter_by(id=tournament_id).first()
+ if team is None:
+ abort(404)
+ elif tournament is None:
+ abort(404)
+
+ if request.method is 'POST':
+ db.session.delete(team)
+ db.session.commit()
+ flash("Deleted")
+ return redirect('setup.manage_tournament', id=tournament_id)
+
+ return render_template('setup/delete_team.html', title=f"Delete team {team}", team=team, tournament=tournament)<
\ No newline at end of file
@@ 2,6 2,10 @@ from flask_wtf import FlaskForm
from wtforms.fields import StringField, IntegerField
from wtforms.validators import DataRequired
+from wtforms_alchemy import ModelForm
+
+from fllscoring.models import Team
+
class NewTournamentForm(FlaskForm):
tournament_name = StringField(label="Name", validators=[DataRequired()])
@@ 10,3 14,7 @@ class NewTeamForm(FlaskForm):
team_number = IntegerField(label="Team Number", validators=[DataRequired()])
team_name = StringField(label="Team Nickname")
team_town = StringField(label="Team Town")
+
+class EditTeamForm(ModelForm):
+ class Meta:
+ model = Team<
\ No newline at end of file
@@ 0,0 1,11 @@
+{% extends 'base.html' %}
+
+{% block content %}
+<h1>Are you sure you want to delete this team?</h1>
+<span class="hbar">
+ <a href="{{ url_for('setup.manage_tournament', id=tournament.id) }}" class="paper movable">No</a>
+ <form method="POST">
+ <input type="submit" class="paper movable accent" value="Yes">
+ </form>
+</span>
+{% endblock %}<
\ No newline at end of file