-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
114 lines (80 loc) · 3.63 KB
/
app.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
from flask import Flask, render_template, request, redirect, url_for
from flask_bootstrap import Bootstrap
from bson import ObjectId
import re
import data_connector, matcher
app = Flask(__name__)
app.config.from_mapping(SECRET_KEY=b'\xd6\x04\xbdj\xfe\xed$c\x1e@\xad\x0f\x13,@G')
# data_connector.clear()
@app.route('/<string:database>/register', methods=['POST'])
def registration(database):
data_connector.new_player(request.form.get('name'), database)
return redirect(url_for('show_players', database=database))
@app.route('/starttournament', methods=['POST'])
def start_tournament():
tournament_name = request.form.get('tournament_name')
tournament_name = re.sub(r'\W+', '', tournament_name)
if tournament_name:
return redirect('/' + tournament_name + '/home')
else:
return redirect('/')
@app.route('/')
@app.route('/home')
def home(database=None):
return render_template('welcome.html', database=database)
@app.route('/<string:database>/home')
def start(database=None):
return render_template('start.html', database=database)
@app.route('/<string:database>/players')
def show_players(database):
players = data_connector.all_players(database)
return render_template('players.html', database=database, players=players)
@app.route('/<string:database>/markertoggle/<string:player_id>/<string:marker>')
def change_marker(database, player_id, marker):
data_connector.change_marker(ObjectId(player_id), marker, database)
return redirect(url_for('show_players', database=database))
@app.route('/<string:database>/matches')
def show_matches(database):
matches = data_connector.matches_with_names(database)
return render_template('matches.html', database=database, matches=matches)
@app.route('/<string:database>/deletematch/<string:match_id>')
def delete_match(database, match_id):
data_connector.delete_match(ObjectId(match_id), database)
matches = data_connector.matches_with_names(database)
return redirect(url_for('show_matches', database=database))
@app.route('/<string:database>/config')
def show_config(database):
config = matcher.tournament_config(database)
return render_template('config.html', database=database, config=config)
@app.route('/datausage')
@app.route('/<string:database>/datausage')
def show_datausage(database=None):
return render_template('datausage.html', database=database)
@app.route('/contact')
@app.route('/<string:database>/contact')
def show_contact(database=None):
return render_template('contact.html', database=database)
@app.route('/<string:database>/cleardata')
def clear_data(database):
data_connector.clear(database)
return show_players(database)
@app.route('/<string:database>/playertoggle/<string:player_id>')
def toggle_player(database, player_id):
data_connector.toggle_player(ObjectId(player_id), database)
return redirect(url_for('show_players', database=database))
@app.route('/<string:database>/result/<string:match_id>/<string:winner>')
def result(database, match_id, winner):
if winner == 'a':
data_connector.match_result(ObjectId(match_id), True, False, database)
else:
data_connector.match_result(ObjectId(match_id), False, True, database)
# show the post with the given id, the id is an integer
return redirect(url_for('show_matches', database=database))
@app.route('/<string:database>/nextgame')
def next_game(database):
next_match = matcher.next_match(data_connector.free_players(database), database)
if next_match:
data_connector.new_match(next_match, database)
return redirect(url_for('show_matches', database=database))
if __name__ == '__main__':
app.run()