Add vote records to session DB

This commit is contained in:
Jonathan Ervine 2020-11-25 22:43:19 +08:00
parent f9aa709a4b
commit 57605fce0e

View File

@ -141,8 +141,10 @@ def hkfcDMotmAdmin():
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 = "SELECT motmUrlSuffix FROM hkfcDAdminSettings WHERE userid='admin'"
tempSuffix = sql_read_static(sql5)
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']
print(currSuffix)
flash('Man of the Match vote is now activated')
@ -237,7 +239,33 @@ def hkfcD_vote_thanks():
prev_identity = request.cookies.get('sessionID')
warn(prev_identity)
if prev_identity:
warn("Naughty, naughty, you've already voted!")
vote_query = "SELECT dotd_" + _matchDate + " FROM motmSessions WHERE sessionID='" + prev_identity + "'"
vote_check = sql_read(vote_query)
if vote_check:
warn("Naughty, naughty, you've already voted!")
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', identity, expires=expire_date)
return resp
else:
identity = randomUrlSuffix(8)
id_commit = "INSERT INTO motmSessions (sessionID) VALUES ('" + identity + "')"