1
- from flask import Flask , render_template , request , url_for , flash , redirect
2
- from datetime import datetime
3
- from DataHandler import DataHandler
4
- from CommunicationHandler import CommunicationHandler
5
- import threading
6
1
import json
2
+ import threading
3
+ from datetime import datetime
4
+
5
+ from flask import Flask , render_template , request , url_for , flash , redirect
7
6
from waitress import serve
8
7
8
+ from CommunicationHandler import CommunicationHandler
9
+ from DataHandler import DataHandler
10
+
9
11
app = Flask (__name__ )
10
12
app .config ["DEBUG" ] = False
11
13
app .config ['SECRET_KEY' ] = 'blah'
23
25
###############################################################
24
26
@app .route ('/' , methods = ['GET' , 'POST' ])
25
27
def index ():
28
+ # homepage
26
29
print ('[index]' )
27
30
return render_template ('home.html' )
28
31
@@ -32,10 +35,12 @@ def index():
32
35
###############################################################
33
36
@app .route ('/tournament_json' , methods = ['GET' ])
34
37
def tournament_json ():
38
+ # tournament, results and referees in json format
35
39
print ('[tournament_json]' )
36
40
conn = dataHandler .get_db_connection ('schedule' )
37
41
cursor = conn .cursor ()
38
42
test = cursor .execute ('SELECT day, starttime, referee FROM schedule' ).fetchall ()
43
+ conn .close ()
39
44
return json .dumps ([dict (ix ) for ix in test ])
40
45
41
46
@@ -44,6 +49,7 @@ def tournament_json():
44
49
###############################################################
45
50
@app .route ('/tournament_overview' , methods = ['GET' ])
46
51
def tournament ():
52
+ # overview of the tournament in table format
47
53
print ('[tournament_overview]' )
48
54
conn = dataHandler .get_db_connection ('schedule' )
49
55
schedule = conn .execute ('SELECT * FROM schedule ORDER BY day, starttime' ).fetchall ()
@@ -56,6 +62,7 @@ def tournament():
56
62
###############################################################
57
63
@app .route ('/results' , methods = ['GET' , 'POST' ])
58
64
def results ():
65
+ # form where teams can fill in the results of the match
59
66
print ('[results]' )
60
67
conn = dataHandler .get_db_connection ('schedule' )
61
68
cursor = conn .cursor ()
@@ -68,6 +75,8 @@ def results():
68
75
score_a = request .form ['score_a' ]
69
76
score_b = request .form ['score_b' ]
70
77
78
+ print ('[main][results] Got results for' , team_a , '-' , team_b , 'at' , date , '' , starttime )
79
+
71
80
# check if combination of data exists
72
81
cursor .execute (
73
82
'SELECT rowid FROM schedule WHERE teamA = ? AND teamB = ? AND starttime = ? AND day = ? AND scoreTeamA IS NULL AND scoreTeamB IS NULL' ,
@@ -91,7 +100,7 @@ def results():
91
100
# flash('This game has not yet started!')
92
101
elif len (rows ) == 0 :
93
102
flash ('Match does not exist or score is already set' )
94
- else :
103
+ else : # send to 'check the results' page
95
104
return redirect (url_for ('check_results' , team_a = team_a , team_b = team_b , date = date ,
96
105
starttime = starttime , score_a = score_a , score_b = score_b ))
97
106
@@ -100,8 +109,8 @@ def results():
100
109
101
110
@app .route ('/check_results' , methods = ['GET' , 'POST' ])
102
111
def check_results ():
112
+ # make sure that the results are correctly implemented
103
113
print ('[check_results]' )
104
- # parsing as function arguments was apparently not ok
105
114
team_a = request .args ['team_a' ]
106
115
team_b = request .args ['team_b' ]
107
116
date = request .args ['date' ]
@@ -124,7 +133,7 @@ def check_results():
124
133
conn .commit ()
125
134
conn .close ()
126
135
commHandler .new_match_results = True
127
- return redirect (url_for ('tournament' ))
136
+ return redirect (url_for ('tournament' )) # send back to tournament overview
128
137
129
138
return render_template ('check_results.html' , team_a = team_a , team_b = team_b , date = date ,
130
139
starttime = starttime , score_a = score_a , score_b = score_b )
@@ -135,6 +144,7 @@ def check_results():
135
144
###############################################################
136
145
@app .route ('/request_friendly' , methods = ['GET' , 'POST' ])
137
146
def request_friendly ():
147
+ # form where teams can request a friendly match
138
148
print ('[request_friendly]' )
139
149
if request .method == 'POST' :
140
150
team_a = request .form ['team_a' ]
@@ -145,12 +155,14 @@ def request_friendly():
145
155
# send a warning if something is missing
146
156
if not team_a :
147
157
flash ('Team A is required!' )
148
- if not team_b :
158
+ elif not team_b :
149
159
flash ('Team B is required!' )
150
- if not date :
160
+ elif not date :
151
161
flash ('Date is required!' )
152
- if not starttime :
162
+ elif not starttime :
153
163
flash ('Time is required!' )
164
+ elif (datetime .now () < datetime .strptime ('2021-06-23 00:00' , '%Y-%m-%d %H:%M' )):
165
+ flash ('You can only request friendlies after 23-06-2021!' )
154
166
else :
155
167
return redirect (url_for ('check_friendly' , team_a = team_a , team_b = team_b , date = date , starttime = starttime ))
156
168
0 commit comments