diff --git a/routes/_hkfcD_motm.py b/routes/_hkfcD_motm.py index 47b95e3..70a6afb 100644 --- a/routes/_hkfcD_motm.py +++ b/routes/_hkfcD_motm.py @@ -310,9 +310,10 @@ def hkfcD_vote_chicken(): 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) + 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!") @@ -329,7 +330,7 @@ def hkfcD_vote_chicken(): 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) + ### 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) @@ -337,32 +338,31 @@ def hkfcD_vote_chicken(): 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: - 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 + 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: