Skip to content

Commit 607f02c

Browse files
committed
only add friendlies after 23/06
1 parent 68d8e78 commit 607f02c

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

main.py

+23-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
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
61
import json
2+
import threading
3+
from datetime import datetime
4+
5+
from flask import Flask, render_template, request, url_for, flash, redirect
76
from waitress import serve
87

8+
from CommunicationHandler import CommunicationHandler
9+
from DataHandler import DataHandler
10+
911
app = Flask(__name__)
1012
app.config["DEBUG"] = False
1113
app.config['SECRET_KEY'] = 'blah'
@@ -23,6 +25,7 @@
2325
###############################################################
2426
@app.route('/', methods=['GET', 'POST'])
2527
def index():
28+
# homepage
2629
print('[index]')
2730
return render_template('home.html')
2831

@@ -32,10 +35,12 @@ def index():
3235
###############################################################
3336
@app.route('/tournament_json', methods=['GET'])
3437
def tournament_json():
38+
# tournament, results and referees in json format
3539
print('[tournament_json]')
3640
conn = dataHandler.get_db_connection('schedule')
3741
cursor = conn.cursor()
3842
test = cursor.execute('SELECT day, starttime, referee FROM schedule').fetchall()
43+
conn.close()
3944
return json.dumps([dict(ix) for ix in test])
4045

4146

@@ -44,6 +49,7 @@ def tournament_json():
4449
###############################################################
4550
@app.route('/tournament_overview', methods=['GET'])
4651
def tournament():
52+
# overview of the tournament in table format
4753
print('[tournament_overview]')
4854
conn = dataHandler.get_db_connection('schedule')
4955
schedule = conn.execute('SELECT * FROM schedule ORDER BY day, starttime').fetchall()
@@ -56,6 +62,7 @@ def tournament():
5662
###############################################################
5763
@app.route('/results', methods=['GET', 'POST'])
5864
def results():
65+
# form where teams can fill in the results of the match
5966
print('[results]')
6067
conn = dataHandler.get_db_connection('schedule')
6168
cursor = conn.cursor()
@@ -68,6 +75,8 @@ def results():
6875
score_a = request.form['score_a']
6976
score_b = request.form['score_b']
7077

78+
print('[main][results] Got results for', team_a, '-', team_b, 'at', date, '', starttime)
79+
7180
# check if combination of data exists
7281
cursor.execute(
7382
'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():
91100
# flash('This game has not yet started!')
92101
elif len(rows) == 0:
93102
flash('Match does not exist or score is already set')
94-
else:
103+
else: # send to 'check the results' page
95104
return redirect(url_for('check_results', team_a=team_a, team_b=team_b, date=date,
96105
starttime=starttime, score_a=score_a, score_b=score_b))
97106

@@ -100,8 +109,8 @@ def results():
100109

101110
@app.route('/check_results', methods=['GET', 'POST'])
102111
def check_results():
112+
# make sure that the results are correctly implemented
103113
print('[check_results]')
104-
# parsing as function arguments was apparently not ok
105114
team_a = request.args['team_a']
106115
team_b = request.args['team_b']
107116
date = request.args['date']
@@ -124,7 +133,7 @@ def check_results():
124133
conn.commit()
125134
conn.close()
126135
commHandler.new_match_results = True
127-
return redirect(url_for('tournament'))
136+
return redirect(url_for('tournament')) # send back to tournament overview
128137

129138
return render_template('check_results.html', team_a=team_a, team_b=team_b, date=date,
130139
starttime=starttime, score_a=score_a, score_b=score_b)
@@ -135,6 +144,7 @@ def check_results():
135144
###############################################################
136145
@app.route('/request_friendly', methods=['GET', 'POST'])
137146
def request_friendly():
147+
# form where teams can request a friendly match
138148
print('[request_friendly]')
139149
if request.method == 'POST':
140150
team_a = request.form['team_a']
@@ -145,12 +155,14 @@ def request_friendly():
145155
# send a warning if something is missing
146156
if not team_a:
147157
flash('Team A is required!')
148-
if not team_b:
158+
elif not team_b:
149159
flash('Team B is required!')
150-
if not date:
160+
elif not date:
151161
flash('Date is required!')
152-
if not starttime:
162+
elif not starttime:
153163
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!')
154166
else:
155167
return redirect(url_for('check_friendly', team_a=team_a, team_b=team_b, date=date, starttime=starttime))
156168

0 commit comments

Comments
 (0)