gcp-hockey-results/routes/_hkfcD_motm.py
2020-12-11 10:51:21 +08:00

469 lines
26 KiB
Python

#import MySQLdb
import pymysql
import os
import json
import datetime
from datetime import datetime, timedelta
from flask import render_template, request, jsonify, flash, make_response
from flask_basicauth import BasicAuth
from app import app, randomUrlSuffix
from readSettings import mySettings
from dbWrite import sql_write, sql_write_static, sql_read, sql_read_static
from tables import matchSquadTable, convenorFixtureList
from forms import adminSettingsForm, motmForm, goalsAssistsForm, adminSettingsForm2
from logging import warn, error
from . import routes
app.config['BASIC_AUTH_USERNAME'] = 'admin'
app.config['BASIC_AUTH_PASSWORD'] = 'letmein'
basic_auth = BasicAuth(app)
@routes.route('/hkfc-d/motm/<randomUrlSuffix>')
def hkfcD_motm_vote(randomUrlSuffix):
squadPlayer_lookup = "SELECT playerNumber, playerForenames, playerSurname, playerNickname FROM _hkfcD_matchSquad ORDER BY RAND()"
settings_lookup = "SELECT nextClub, nextTeam, nextDate, oppoLogo, hkfcLogo, currMotM, currDotD, nextFixture FROM hkfcDAdminSettings"
nextFixture_lookup = "SELECT hockeyResults2020.hockeyFixtures.date, hockeyResults.hkfcDAdminSettings.nextFixture FROM hockeyResults2020.hockeyFixtures INNER JOIN hockeyResults.hkfcDAdminSettings ON hockeyResults2020.hockeyFixtures.fixtureNumber = hockeyResults.hkfcDAdminSettings.nextFixture"
motmPicture_lookup = "SELECT playerPictureURL FROM _HKFC_players INNER JOIN hockeyResults.hkfcDAdminSettings ON _HKFC_players.playerNumber=hockeyResults.hkfcDAdminSettings.currMotM"
dotdPicture_lookup = "SELECT playerPictureURL FROM _HKFC_players INNER JOIN hockeyResults.hkfcDAdminSettings ON _HKFC_players.playerNumber=hockeyResults.hkfcDAdminSettings.currDotD"
comments_lookup = "SELECT comment FROM _motmComments INNER JOIN hockeyResults.hkfcDAdminSettings ON _motmComments.matchDate=hockeyResults.hkfcDAdminSettings.nextDate ORDER BY RAND() LIMIT 1"
urlSuffix_lookup = "SELECT motmUrlSuffix FROM hockeyResults.hkfcDAdminSettings WHERE userid='admin'"
rows = sql_read(squadPlayer_lookup)
nextInfo = sql_read_static(settings_lookup)
nextClub = nextInfo[0]['nextClub']
nextTeam = nextInfo[0]['nextTeam']
nextFixture = nextInfo[0]['nextFixture']
hkfcLogo = nextInfo[0]['hkfcLogo']
oppoLogo = nextInfo[0]['oppoLogo']
currMotM = nextInfo[0]['currMotM']
currDotD = nextInfo[0]['currDotD']
oppo = nextTeam
nextMatchDate = sql_read(nextFixture_lookup)
nextDate = nextMatchDate[0]['date']
formatDate = datetime.strftime(nextDate, '%A, %d %B %Y')
motm = sql_read(motmPicture_lookup)
dotd = sql_read(dotdPicture_lookup)
motmURL = motm[0]['playerPictureURL']
dotdURL = dotd[0]['playerPictureURL']
comment = sql_read(comments_lookup)
if comment == "":
comment = "No comments added yet"
form = motmForm()
urlSuff = sql_read_static(urlSuffix_lookup)
randomSuff = urlSuff[0]['motmUrlSuffix']
if randomSuff == randomUrlSuffix:
return render_template('_hkfcDMotmVote.html', data=rows, comment=comment, formatDate=formatDate, matchNumber=nextFixture, oppo=oppo, hkfcLogo=hkfcLogo, oppoLogo=oppoLogo, dotdURL=dotdURL, motmURL=motmURL, form=form)
else:
return render_template('_error.html')
@routes.route('/hkfc-d/comments', methods=['GET', 'POST'])
def hkfcd_match_comments():
settings_lookup = "SELECT nextClub, nextTeam, nextDate, oppoLogo, hkfcLogo FROM hkfcDAdminSettings"
row = sql_read_static(settings_lookup)
# nextTeam already seems to include all the team+club details
# _oppo = row[0]['nextClub'] + " " + row[0]['nextTeam']
_oppo = row[0]['nextClub']
commentDate = row[0]['nextDate'].strftime('%Y-%m-%d')
_matchDate = row[0]['nextDate'].strftime('%Y_%m_%d')
hkfcLogo = row[0]['hkfcLogo']
oppoLogo = row[0]['oppoLogo']
comment_insert = "INSERT INTO _motmComments (matchDate, opposition, comment) VALUES ('" + commentDate + "', '" + _oppo + "', '" + _fixed_comment + "')"
comment_lookup = "SELECT comment FROM _motmComments WHERE matchDate='" + _matchDate + "' ORDER BY RAND()"
if request.method == 'POST':
_comment = request.form['matchComment']
if _comment != 'Optional comments added here':
_fixed_comment = _comment.replace("'", "\\'")
sql_write(comment_insert)
comments = sql_read(comment_lookup)
return render_template('_hkfcDMatchComments.html', comments=comments, hkfcLogo=hkfcLogo, oppoLogo=oppoLogo)
@routes.route('/hkfc-d/statAdmin', methods=['GET', 'POST'])
def hkfc_d_stats_admin():
form = goalsAssistsForm()
fixtures_lookup = "SELECT date, homeTeam, awayTeam, venue, fixtureNumber FROM hockeyFixtures WHERE homeTeam='HKFC D' OR awayTeam='HKFC D'"
squadPlayer_lookup = "SELECT playerNumber, playerNickname FROM _hkfcD_matchSquad"
matches = sql_read(fixtures_lookup)
form.match.choices = [(match['fixtureNumber'], match['date']) for match in matches]
players = sql_read(squadPlayer_lookup)
return render_template('_goalsAssistsAdmin.html', data=players, form=form)
@routes.route('/hkfc-d/goalsAssistsSubmit', methods=['POST'])
def goalsAssistsSubmit():
try:
data = request.form
playerName = request.form.getlist('playerName')
playerNumber = request.form.getlist('playerNumber')
assists = request.form.getlist('assists')
goals = request.form.getlist('goals')
match = request.form['match']
playerGoalsAssists_update = "INSERT INTO _hkfc_d_motm (playerNumber, playerName, assistsTotal, goalsTotal, assists_" + match + ", goals_" + match + ") SELECT playerNumber, playerNickname, '" + assists[idx] + "', '" + goals[idx] + "', '" + assists[idx] + "', '" + goals[idx] + "' FROM _HKFC_players WHERE playerNumber='" + player + "' ON DUPLICATE KEY UPDATE assistsTotal = assistsTotal + " + assists[idx] + ", goalsTotal = goalsTotal + " + goals[idx] + ", assists_" + match + " = " + assists[idx] + ", goals_" + match + " = " + goals[idx] + ""
for idx, player in enumerate(playerNumber):
sql_write(playerGoalsAssists_update)
except Exception as e:
print(e)
finally:
return render_template('_hkfcDGoalsThanks.html', data=data)
@routes.route('/hkfc-d/motmAdmin', methods=['GET', 'POST'])
def hkfcDMotmAdmin():
form = adminSettingsForm2()
prevFixture = mySettings('prevFixture')
if prevFixture is None:
prevFixture = '1'
else:
prevFixture = str(prevFixture)
if request.method == 'POST':
if form.saveButton.data:
print('Saved')
else:
print('Activated')
_nextTeam = request.form['nextOppoTeam']
_nextFixture = request.form['nextMatch']
_currMotM = request.form['currMotM']
_currDotD = request.form['currDotD']
sql1 = "SELECT club FROM _clubTeams WHERE displayName='" + _nextTeam + "'"
_nextClubName = sql_read_static(sql1)
_nextClub = _nextClubName[0]['club']
sql = "UPDATE hkfcDAdminSettings SET nextFixture='" + _nextFixture + "', nextClub='" + _nextClub + "', nextTeam='" + _nextTeam + "', currMotM=" + _currMotM + ", currDotD=" + _currDotD + ""
sql_write_static(sql)
sql2 = "UPDATE hkfcDAdminSettings INNER JOIN mensHockeyClubs ON hkfcDAdminSettings.nextClub = mensHockeyClubs.hockeyClub SET hkfcDAdminSettings.oppoLogo = mensHockeyClubs.logoURL WHERE mensHockeyClubs.hockeyClub='" + _nextClub + "'"
sql_write_static(sql2)
if form.saveButton.data:
flash('Settings saved!')
urlSuffix = randomUrlSuffix(8)
sql3 = "UPDATE hkfcDAdminSettings SET motmUrlSuffix='" + urlSuffix + "' WHERE userid='admin'"
sql_write_static(sql3)
flash('MotM URL https://hockey.ervine.dev/hkfc-d/motm/'+urlSuffix)
elif form.activateButton.data:
sql4 = "ALTER TABLE _hkfc_d_motm ADD COLUMN motm_" + _nextFixture + " smallint DEFAULT 0, ADD COLUMN dotd_" + _nextFixture + " smallint DEFAULT 0, ADD COLUMN assists_" + _nextFixture + " smallint DEFAULT 0, ADD COLUMN goals_" + _nextFixture + " smallint DEFAULT 0 "
sql_write(sql4)
sql5 = "ALTER TABLE motmSessions ADD COLUMN motm_" + _nextFixture + " smallint DEFAULT NULL, ADD COLUMN dotd_" + _nextFixture + " smallint DEFAULT NULL "
sql_write(sql5)
sql6 = "SELECT motmUrlSuffix FROM hkfcDAdminSettings WHERE userid='admin'"
tempSuffix = sql_read_static(sql6)
currSuffix = tempSuffix[0]['motmUrlSuffix']
flash('Man of the Match vote is now activated')
flash('MotM URL https://hockey.ervine.dev/hkfc-d/motm/'+currSuffix)
else:
flash('Something went wrong - check with Smithers')
sql7 = "SELECT date, homeTeam, awayTeam, venue, fixtureNumber FROM hockeyFixtures WHERE homeTeam='HKFC D' OR awayTeam='HKFC D'"
matches = sql_read(sql7)
form.nextMatch.choices = [(match['fixtureNumber'], match['date']) for match in matches]
sql4 = "SELECT hockeyClub FROM mensHockeyClubs ORDER BY hockeyClub"
sql5 = "SELECT nextClub, oppoLogo FROM hkfcDAdminSettings"
sql6 = "SELECT playerNumber, playerForenames, playerSurname FROM _hkfcD_matchSquad_" + prevFixture + " ORDER BY playerForenames"
clubs = sql_read_static(sql4)
settings = sql_read_static(sql5)
players = sql_read(sql6)
form.nextOppoClub.choices = [(oppo['hockeyClub'], oppo['hockeyClub']) for oppo in clubs]
form.currMotM.choices = [(player['playerNumber'], player['playerForenames'] + " " + player['playerSurname']) for player in players]
form.currDotD.choices = [(player['playerNumber'], player['playerForenames'] + " " + player['playerSurname']) for player in players]
clubLogo = settings[0]['oppoLogo']
return render_template('_hkfcDMotmAdmin.html', form=form, nextOppoLogo=clubLogo)
@routes.route('/hkfc-d/motmAdmin/<club>')
def hkfc_d_admin_team(club):
sql = "SELECT team FROM _clubTeams WHERE club='" + club + "'"
myteams = sql_read(sql)
return jsonify(myteams)
@routes.route('/hkfc-d/getLogo/<club>')
def hkfc_d_get_logo(club):
sql = "SELECT logoURL FROM mensHockeyClubs WHERE hockeyClub='" + club + "'"
clubLogo = sql_read(sql)
return jsonify(clubLogo)
@routes.route('/hkfc-d/motmAdmin2/<fixture>')
def hkfc_d_admin_team2(fixture):
sql = "SELECT homeTeam, awayTeam FROM hockeyFixtures WHERE fixtureNumber='" + fixture + "'"
myteams = sql_read(sql)
if myteams[0]['homeTeam'].startswith("HKFC"):
nextOppo = myteams[0]['awayTeam']
else:
nextOppo = myteams[0]['homeTeam']
sql2 = "SELECT club FROM _clubTeams WHERE displayName ='" + nextOppo + "'"
return jsonify(nextOppo)
@routes.route('/hkfc-d/motmAdminLogo2/<fixture>')
def hkfc_d_admin_logo2(fixture):
sql = "SELECT homeTeam, awayTeam FROM hockeyFixtures WHERE fixtureNumber='" + fixture + "'"
myteams = sql_read(sql)
if myteams[0]['homeTeam'].startswith("HKFC D"):
nextOppo = myteams[0]['awayTeam']
else:
nextOppo = myteams[0]['homeTeam']
sql2 = "SELECT club FROM _clubTeams WHERE displayName ='" + nextOppo + "'"
clubs = sql_read_static(sql2)
clubName = clubs[0]['club']
sql3 = "SELECT logoUrl FROM mensHockeyClubs WHERE hockeyClub ='" + clubName + "'"
logo = sql_read_static(sql3)
clubLogo = logo[0]['logoUrl']
return jsonify(clubLogo)
@routes.route('/hkfc-d/statsAdmin/<fixture>')
def hkfc_dstatsAdminLookup(fixture):
sql = "SELECT homeTeam, awayTeam FROM hockeyFixtures WHERE fixtureNumber='" + fixture + "'"
teams = sql_read(sql)
#### The below SQL could be used to try and populate the team sheet for goals and assists after the match has been committed. TODO
# sql2 = "SELECT playerNumber, playerNickname FROM _hkfcD_matchSquad_" + fixture + ""
# players = sql_read(sql2)
# return jsonify(teams, players)
#### Return the teams to the javascript code.
return jsonify(teams)
@routes.route('/hkfc-d/vote-thanks', methods=['POST'])
def hkfcD_vote_thanks():
try:
_motm = request.form['motmVote']
_dotd = request.form['dotdVote']
_comments = request.form['motmComment']
_fixed_comments = _comments.replace("'", "\\'")
_matchDate = request.form['matchNumber']
_oppo = request.form['oppo']
if _motm and _dotd and request.method == 'POST':
prev_identity = request.cookies.get('sessionID')
user_agent = request.headers.get('User-Agent')
if prev_identity:
warn("Previous identity found: "+prev_identity)
vote_query = "SELECT dotd_" + _matchDate + " FROM motmSessions WHERE sessionID='" + prev_identity + "'"
vote_check = sql_read(vote_query)
if not vote_check:
warn('Cookie exists but no record in DB - check: '+prev_identity)
return render_template('_hkfcDSmithersFail.html', sessionID=prev_identity)
else:
vote_valid = vote_check[0]['dotd_' + _matchDate ]
if vote_valid:
warn("Naughty, naughty, you've already voted!")
return render_template('_hkfcDVoteFraud.html', sessionID=prev_identity)
else:
sql = "INSERT INTO _hkfc_d_motm (playerNumber, playerName, motmTotal, motm_" + _matchDate + ") SELECT playerNumber, playerNickname, '1', '1' FROM _HKFC_players WHERE playerNumber='" + _motm + "' ON DUPLICATE KEY UPDATE motmTotal = motmTotal + 1, motm_" + _matchDate + " = motm_" + _matchDate + " + 1"
sql2 = "INSERT INTO _hkfc_d_motm (playerNumber, playerName, dotdTotal, dotd_" + _matchDate + ") SELECT playerNumber, playerNickname, '1', '1' FROM _HKFC_players WHERE playerNumber='" + _dotd + "' ON DUPLICATE KEY UPDATE dotdTotal = dotdTotal + 1, dotd_" + _matchDate + " = dotd_" + _matchDate + " + 1"
sql4 = "UPDATE motmSessions SET motm_" + _matchDate + "=" + _motm + " WHERE sessionID='" + prev_identity + "'"
sql5 = "UPDATE motmSessions SET dotd_" + _matchDate + "=" + _dotd + " WHERE sessionID='" + prev_identity + "'"
sql_write(sql4)
sql_write(sql5)
if _comments == "":
print("No comment")
elif _comments == "Optional comments added here":
print("No comment")
else:
### The matchDate has been replaced with the matchNumber - this should be corrected at some point (via a fixture table lookup)
sql3 = "INSERT INTO _motmComments (_matchDate, opposition, comment) VALUES ('" + _matchDate + "', '" + _oppo + "', '" + _fixed_comments + "')"
sql_write(sql3)
sql_write(sql)
sql_write(sql2)
resp = make_response(render_template('_hkfcDVoteThanks.html'))
expire_date = datetime.now()
expire_date = expire_date + timedelta(days=90)
resp.set_cookie('sessionID', prev_identity, expires=expire_date)
return resp
else:
identity = randomUrlSuffix(8)
print("Identity: " + identity)
print("User Agent: " + user_agent)
warn("Identity and User-Agent set")
id_commit = "INSERT INTO motmSessions (sessionID, userAgent, motm_" + _matchDate + ", dotd_" + _matchDate + ") VALUES ('" + identity + "', '" + user_agent + "', '" + _motm + "', '" + _dotd + "' )"
sql_write(id_commit)
sql = "INSERT INTO _hkfc_d_motm (playerNumber, playerName, motmTotal, motm_" + _matchDate + ") SELECT playerNumber, playerNickname, '1', '1' FROM _HKFC_players WHERE playerNumber='" + _motm + "' ON DUPLICATE KEY UPDATE motmTotal = motmTotal + 1, motm_" + _matchDate + " = motm_" + _matchDate + " + 1"
sql2 = "INSERT INTO _hkfc_d_motm (playerNumber, playerName, dotdTotal, dotd_" + _matchDate + ") SELECT playerNumber, playerNickname, '1', '1' FROM _HKFC_players WHERE playerNumber='" + _dotd + "' ON DUPLICATE KEY UPDATE dotdTotal = dotdTotal + 1, dotd_" + _matchDate + " = dotd_" + _matchDate + " + 1"
if _comments == "":
print("No comment")
elif _comments == "Optional comments added here":
print("No comment")
else:
### The matchDate has been replaced with the matchNumber - this should be corrected at some point (via a fixture table lookup)
sql3 = "INSERT INTO _motmComments (_matchDate, opposition, comment) VALUES ('" + _matchDate + "', '" + _oppo + "', '" + _fixed_comments + "')"
#sql_write(sql3)
#sql_write(sql)
#sql_write(sql2)
resp = make_response(render_template('_hkfcDVoteThanks.html'))
expire_date = datetime.now()
expire_date = expire_date + timedelta(days=90)
resp.set_cookie('sessionID', identity, expires=expire_date)
return resp
else:
return 'Ouch ... something went wrong here'
except Exception as e:
print(e)
finally:
print('Votes cast - thanks')
@routes.route('/hkfc-d/vote-chicken', methods=['GET', 'POST'])
def hkfcD_vote_chicken():
try:
prev_identity = request.cookies.get('sessionID')
user_agent = request.headers.get('User-Agent')
nextFixture = "SELECT nextFixture FROM hkfcDAdminSettings"
_matchDate = sql_read_static(nextFixture)
if prev_identity:
vote_query = "SELECT dotd_" + _matchDate + " FROM motmSessions WHERE sessionID='" + prev_identity + "'"
vote_check = sql_read(vote_query)
if not vote_check:
warn('Cookie exists but no record in DB - check: '+prev_identity)
return render_template('_hkfcDSmithersFail.html', sessionID=prev_identity)
else:
vote_valid = vote_check[0]['dotd_' + _matchDate ]
if vote_valid:
warn("Naughty, naughty, you've already voted!")
return render_template('_hkfcDVoteFraud.html', sessionID=prev_identity)
else:
sql = "INSERT INTO _hkfc_d_motm (playerNumber, playerName, motmTotal, motm_" + _matchDate + ") SELECT playerNumber, playerNickname, '1', '1' FROM _HKFC_players WHERE playerNumber='" + _motm + "' ON DUPLICATE KEY UPDATE motmTotal = motmTotal + 1, motm_" + _matchDate + " = motm_" + _matchDate + " + 1"
sql2 = "INSERT INTO _hkfc_d_motm (playerNumber, playerName, dotdTotal, dotd_" + _matchDate + ") SELECT playerNumber, playerNickname, '1', '1' FROM _HKFC_players WHERE playerNumber='" + _dotd + "' ON DUPLICATE KEY UPDATE dotdTotal = dotdTotal + 1, dotd_" + _matchDate + " = dotd_" + _matchDate + " + 1"
sql4 = "UPDATE motmSessions SET motm_" + _matchDate + "=" + _motm + " WHERE sessionID='" + prev_identity + "'"
sql5 = "UPDATE motmSessions SET dotd_" + _matchDate + "=" + _dotd + " WHERE sessionID='" + prev_identity + "'"
sql_write(sql4)
sql_write(sql5)
if _comments == "":
print("No comment")
elif _comments == "Optional comments added here":
print("No comment")
else:
### The matchDate has been replaced with the matchNumber - this should be corrected at some point (via a fixture table lookup)
sql3 = "INSERT INTO _motmComments (_matchDate, opposition, comment) VALUES ('" + _matchDate + "', '" + _oppo + "', '" + _fixed_comments + "')"
sql_write(sql3)
sql_write(sql)
sql_write(sql2)
resp = make_response(render_template('_hkfcDVoteThanks.html'))
expire_date = datetime.now()
expire_date = expire_date + timedelta(days=90)
resp.set_cookie('sessionID', prev_identity, expires=expire_date)
return resp
else:
identity = randomUrlSuffix(8)
id_commit = "INSERT INTO motmSessions (sessionID) VALUES ('" + identity + "')"
ua_commit = "INSERT INTO motmSessions (userAgent) VALUES ('" + user_agent + "')"
sql_write(id_commit)
sql = "INSERT INTO _hkfc_d_motm (playerNumber, playerName, motmTotal, motm_" + _matchDate + ") SELECT playerNumber, playerNickname, '1', '1' FROM _HKFC_players WHERE playerNumber='" + _motm + "' ON DUPLICATE KEY UPDATE motmTotal = motmTotal + 1, motm_" + _matchDate + " = motm_" + _matchDate + " + 1"
sql2 = "INSERT INTO _hkfc_d_motm (playerNumber, playerName, dotdTotal, dotd_" + _matchDate + ") SELECT playerNumber, playerNickname, '1', '1' FROM _HKFC_players WHERE playerNumber='" + _dotd + "' ON DUPLICATE KEY UPDATE dotdTotal = dotdTotal + 1, dotd_" + _matchDate + " = dotd_" + _matchDate + " + 1"
if _comments == "":
print("No comment")
elif _comments == "Optional comments added here":
print("No comment")
else:
### The matchDate has been replaced with the matchNumber - this should be corrected at some point (via a fixture table lookup)
sql3 = "INSERT INTO _motmComments (_matchDate, opposition, comment) VALUES ('" + _matchDate + "', '" + _oppo + "', '" + _fixed_comments + "')"
sql_write(sql3)
sql_write(sql)
sql_write(sql2)
resp = make_response(render_template('_hkfcDVoteThanks.html'))
expire_date = datetime.now()
expire_date = expire_date + timedelta(days=90)
resp.set_cookie('sessionID', identity, expires=expire_date)
return resp
#else:
#return 'Ouch ... something went wrong here'
except Exception as e:
print(e)
finally:
print('Votes cast')
@routes.route('/hkfc-d/vote-results')
def hkfcD_vote_results():
_matchDate = str(mySettings('fixture'))
sql = "SELECT playerName, motm_" + _matchDate + ", dotd_" + _matchDate + " FROM _hkfc_d_motm WHERE (motm_" + _matchDate + " > '0') OR (dotd_" + _matchDate + " > '0')"
print(sql)
rows = sql_read(sql)
print(rows)
return json.dumps(rows)
@routes.route('/hkfc-d/poty-results')
def hkfcD_poty_results():
sql = "SELECT playerName, motmTotal, dotdTotal FROM _hkfc_d_motm WHERE (motmTotal > '0') OR (dotdTotal > '0')"
print(sql)
rows = sql_read(sql)
return json.dumps(rows)
@routes.route('/hkfc-d/voting')
def hkfcD_voting():
matchDate = mySettings('fixture')
return render_template('_hkfcDVoteChart.html', _matchDate=matchDate)
@routes.route('/hkfc-d/poty')
def hkfcD_poty():
return render_template('_hkfcDPotYChart.html')
@routes.route('/hkfc-d/matchSquad')
def hkfcD_match_squad():
sql1 = "SELECT team from _clubTeams WHERE club='HKFC' ORDER BY team"
sql2 = "SELECT playerTeam, playerForenames, playerSurname, playerNickname, playerNumber FROM _HKFC_players"
teams = sql_read(sql1)
players = sql_read(sql2)
return render_template('_hkfcDMatchSquad.html', teams=teams, players=players)
@routes.route('/hkfc-d/matchSquadSubmit', methods=['POST'])
def hkfcD_match_squad_submit():
_playerNumbers = request.form.getlist('playerNumber')
for _playerNumber in _playerNumbers:
sql = "INSERT INTO _hkfcD_matchSquad (playerNumber, playerForenames, playerSurname, playerNickname) SELECT playerNumber, playerForenames, playerSurname, playerNickname FROM _HKFC_players WHERE playerNumber='" + _playerNumber + "'"
sql_write(sql)
sql2 = "SELECT playerNumber, playerForenames, playerSurname, playerNickname FROM _hkfcD_matchSquad"
players = sql_read(sql2)
table = matchSquadTable(players)
table.border = True
table.classes = ['table-striped', 'table-condensed', 'table-hover']
return render_template('_hkfcDMatchSquadSelected.html', table=table)
@routes.route('/hkfc-d/matchSquadList')
def hkfcD_match_squad_list():
sql = "SELECT playerNumber, playerForenames, playerSurname, playerNickname FROM _hkfcD_matchSquad"
players = sql_read(sql)
table = matchSquadTable(players)
table.border = True
table.classes = ['table-striped', 'table-condensed', 'table-hover']
return render_template('_hkfcDMatchSquadSelected.html', table=table)
@routes.route('/convenor/delPlayerFromSquad', methods=['POST'])
def delPlayerFromSquad():
_playerNumber = request.args['playerNumber']
sql = "DELETE FROM _hkfcD_matchSquad WHERE playerNumber=" + _playerNumber + ""
sql_write(sql)
return render_template('_hkfcDPlayerRemoved.html', number=_playerNumber)
@routes.route('/hkfc-d/matchSquadReset')
def hkfcD_matchSquadReset():
_matchNumber = str(mySettings('fixture'))
sql1 = "RENAME TABLE _hkfcD_matchSquad TO _hkfcD_matchSquad_" + _matchNumber + ""
sql2 = "CREATE TABLE _hkfcD_matchSquad (playerNumber smallint UNIQUE, playerForenames varchar(50), playerSurname varchar(30), playerNickname varchar(30) NOT NULL, PRIMARY KEY (playerNumber))"
sql3 = "UPDATE hkfcDAdminSettings SET prevFixture='" + _matchNumber + "'"
sql_write(sql1)
sql_write(sql2)
sql_write_static(sql3)
return render_template('_hkfcDMatchSquadReset.html')
@routes.route('/hkfc-d/fixtureList')
def hkfcDFixtures():
sql = "SELECT date, division, homeTeam, awayTeam, venue, time, umpire1, umpire2 FROM hockeyFixtures WHERE homeTeam='HKFC D' OR awayTeam='HKFC D'"
rows = sql_read(sql)
table = convenorFixtureList(rows)
table.border = True
table.classes = ['table-striped', 'table-condensed', 'table-hover']
return render_template('_convenorFixtureList.html', table=table)