-
Notifications
You must be signed in to change notification settings - Fork 1
/
teams.py
59 lines (47 loc) · 1.85 KB
/
teams.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from flask import request, redirect, flash, Blueprint
from db_model import Team, db, Puzzlehunt
from helpers import render, admin_required
teams = Blueprint('teams', __name__, template_folder='templates', static_folder='static')
@teams.route('/teams')
@admin_required
def teams_list():
teams = Team.query.filter_by(id_puzzlehunt=Puzzlehunt.get_current_id()).order_by(Team.name).all()
return render("teams.html", teams=teams)
@teams.route('/teams/new', methods=("GET", "POST"))
@admin_required
def teams_new():
if request.method == "POST":
team = Team(Puzzlehunt.get_current_id(), request.form["name"], request.form["password"], request.form["phone"], request.form["note"])
db.session.add(team)
db.session.commit()
return redirect("/teams")
return render("team_edit.html")
@teams.route('/teams/<id_team>', methods=("GET", "POST"))
@admin_required
def teams_edit(id_team):
team = Team.query.get(id_team)
if team is None:
flash(f"Tým s id_team={id_team} neexistuje.", "warning")
return redirect("/teams")
if request.method == "POST":
team.name = request.form["name"]
if request.form["password"]:
team.set_password(request.form["password"])
team.phone = request.form["phone"]
team.note = request.form["note"]
db.session.add(team)
db.session.commit()
return redirect("/teams")
else:
return render("team_edit.html", team=team)
@teams.route('/teams/<id_team>/delete', methods=("POST",))
@admin_required
def teams_delete(id_team):
team = Team.query.get(id_team)
if team is None:
flash(f"Tým s id_team={id_team} neexistuje.", "warning")
return redirect("/teams")
db.session.delete(team)
db.session.commit()
flash(f'Tým "{team.name}" (id={team.id}) smazán.', "success")
return redirect("/teams")