gcp-hockey-results/routes/_search.py
Jonny Ervine 1ffa319b1e new file: app.py
new file:   appengine_config.py
	new file:   dbWrite.py
	new file:   forms.py
	new file:   main.py
	new file:   readSettings.py
	new file:   requirements.txt
	new file:   routes/__init__.py
	new file:   routes/_convenor.py
	new file:   routes/_hkfcD_motm.py
	new file:   routes/_matches.py
	new file:   routes/_search.py
	new file:   routes/dashboard.py
	new file:   static/css/bootstrap-theme.css
	new file:   static/css/bootstrap-theme.css.map
	new file:   static/css/bootstrap-theme.min.css
	new file:   static/css/bootstrap-theme.min.css.map
	new file:   static/css/bootstrap.css
	new file:   static/css/bootstrap.css.map
	new file:   static/css/bootstrap.min.css
	new file:   static/css/bootstrap.min.css.map
	new file:   static/css/dashboard.css
	new file:   static/css/dashboard.css.orig
	new file:   static/fonts/glyphicons-halflings-regular.eot
	new file:   static/fonts/glyphicons-halflings-regular.svg
	new file:   static/fonts/glyphicons-halflings-regular.ttf
	new file:   static/fonts/glyphicons-halflings-regular.woff
	new file:   static/fonts/glyphicons-halflings-regular.woff2
	new file:   static/js/bootstrap.js
	new file:   static/js/bootstrap.min.js
	new file:   static/js/dashboard.js
	new file:   static/js/npm.js
	new file:   tables.py
	new file:   templates/_about.html
	new file:   templates/_clubPlayingRecordResults.html
	new file:   templates/_clubPlayingRecords.html
	new file:   templates/_convenorClubAdd.html
	new file:   templates/_convenorClubAddResults.html
	new file:   templates/_convenorClubList.html
	new file:   templates/_convenorEditPlayerResults.html
	new file:   templates/_convenorEditSquadList.html
	new file:   templates/_convenorEditSquadListTeamSelect.html
	new file:   templates/_convenorFixtureList.html
	new file:   templates/_convenorPlayerAdd.html
	new file:   templates/_convenorPlayerAddResults.html
	new file:   templates/_convenorPlayerDbCreate.html
	new file:   templates/_convenorPlayerDbCreateResults.html
	new file:   templates/_convenorPlayerEdit.html
	new file:   templates/_convenorSquadList.html
	new file:   templates/_convenorSquadListResults.html
	new file:   templates/_convenorTeamAdd.html
	new file:   templates/_convenorTeamAddResults.html
	new file:   templates/_error.html
	new file:   templates/_goalsAssistsAdmin.html
	new file:   templates/_hkfcDAdminThanks.html
	new file:   templates/_hkfcDGoalsThanks.html
	new file:   templates/_hkfcDMatchComments.html
	new file:   templates/_hkfcDMatchSquad.html
	new file:   templates/_hkfcDMatchSquadReset.html
	new file:   templates/_hkfcDMatchSquadSelected.html
	new file:   templates/_hkfcDMotmAdmin.html
	new file:   templates/_hkfcDMotmVote.html
	new file:   templates/_hkfcDPlayerRemoved.html
	new file:   templates/_hkfcDPotYChart.html
	new file:   templates/_hkfcDVoteChart.html
	new file:   templates/_hkfcDVoteThanks.html
	new file:   templates/_hkfcPlayerDeleted.html
	new file:   templates/_matchDetails.html
	new file:   templates/_playerCheck.html
	new file:   templates/_playerCheckResults.html
	new file:   templates/_playerRecordResults.html
	new file:   templates/_playerRecords.html
	new file:   templates/_search.html
	new file:   templates/_searchResults.html
	new file:   templates/_teamRecordResults.html
	new file:   templates/_teamRecords.html
	new file:   templates/dashboard.html
	new file:   templates/results.html
	new file:   templates/search.html
Initial commit
2020-02-19 06:58:08 +00:00

168 lines
7.2 KiB
Python

#import MySQLdb
import pymysql
from dbWrite import sql_read, sql_read_static
from flask import render_template, request
from forms import searchForm, playerRecordsForm, teamRecordsForm, clubPlayingRecordsForm
from . import routes
from tables import Results, playerResults, teamResults, clubPlayingRecord
import datetime
from datetime import date
@routes.route('/search')
def search():
sql = "SELECT hockeyClub FROM mensHockeyClubs ORDER BY hockeyClub"
sql2 = "SELECT nextClub, oppoLogo FROM hkfcDAdminSettings"
clubs = sql_read(sql)
settings = sql_read(sql2)
form = searchForm()
form.clubName.choices = [(name['hockeyClub'], name['hockeyClub']) for name in clubs]
clubLogo = settings[0]['oppoLogo']
return render_template('_search.html', data=clubs, selectedClubLogo=clubLogo, form=form)
@routes.route('/searchTeam', methods=['POST'])
def searchTeam():
_season = request.form['season']
_club = request.form['clubName']
_team = request.form['teamName']
_startDate = request.form['startDate']
_endDate = request.form['endDate']
print(request.form)
# validate that this data has been entered
if _club and _team and request.method == 'POST':
sql = "SELECT * FROM _mensResults WHERE (matchDate BETWEEN '" + _startDate + "' AND '" + _endDate + "') AND ((matchHomeClub='" + _club + "' AND matchHomeTeam='" + _team + "') OR (matchAwayClub='" + _club + "' AND matchAwayTeam='" + _team + "')) ORDER BY matchDate"
rows = sql_read(sql)
table = Results(rows)
table.border = True
table.classes = ['table-striped', 'table-condensed', 'table-hover']
return render_template('_searchResults.html', table=table)
else:
return 'Invalid search data entered'
@routes.route('/playerRecords')
def playerRecords():
sql = "SELECT hockeyClub FROM mensHockeyClubs ORDER BY hockeyClub"
sql2 = "SELECT nextClub, oppoLogo FROM hkfcDAdminSettings"
clubs = sql_read(sql)
settings = sql_read(sql2)
form = playerRecordsForm()
form.clubName.choices = [(name['hockeyClub'], name['hockeyClub']) for name in clubs]
clubLogo = settings[0]['oppoLogo']
return render_template('_playerRecords.html', data=clubs, selectedClubLogo=clubLogo, form=form)
@routes.route('/playerRecordSearch', methods=['POST'])
def playerRecordSearchResults():
columnName = {}
matchNumbersList = []
_season = request.form['season']
_club = request.form['clubName']
_team = request.form['teamName']
lookup_table = _club.lower() + _team
if _club and _team and request.method == 'POST':
sql = "SELECT * FROM _" + lookup_table + " ORDER BY playerNumber"
sql2 = "SHOW COLUMNS FROM _" + lookup_table + ""
sql3 = "SELECT matchNumber, matchHomeClub, matchHomeTeam, matchAwayClub, matchAwayTeam FROM _mensResults WHERE (matchHomeClub='" + _club + "' AND matchHomeTeam='" + _team + "') OR (matchAwayClub='" + _club + "' AND matchAwayTeam='" + _team + "')"
rows = sql_read(sql)
columns = sql_read(sql2)
matches = sql_read(sql3)
for match in matches:
matchNumbersList.append(str(match['matchNumber']))
if match['matchHomeClub'] == _club:
columnName[str(match['matchNumber'])] = match['matchAwayClub'] + " " + match['matchAwayTeam']
else:
columnName[str(match['matchNumber'])] = match['matchHomeClub'] + " " + match['matchHomeTeam']
return render_template('_playerRecordResults.html', rows=rows, columns=columns, matches=columnName, matchesList=matchNumbersList)
else:
return 'Invalid search data entered'
@routes.route('/teamRecords')
def teamRecords():
sql = "SELECT hockeyClub FROM mensHockeyClubs ORDER BY hockeyClub"
sql2 = "SELECT nextClub, oppoLogo FROM hkfcDAdminSettings"
clubs = sql_read(sql)
settings = sql_read(sql2)
form = teamRecordsForm()
form.clubName.choices = [(name['hockeyClub'], name['hockeyClub']) for name in clubs]
clubLogo = settings[0]['oppoLogo']
return render_template('_teamRecords.html', data=clubs, selectedClubLogo=clubLogo, form=form)
@routes.route('/teamRecordSearch', methods=['POST'])
def teamRecordResults():
_season = request.form['season']
_club = request.form['clubName']
_team = request.form['teamName']
lookup_table = _club.lower() + _team
if _club and _team and request.method == 'POST':
sql = "SELECT * FROM _record_" + lookup_table + " ORDER BY opposition"
print(sql)
rows = sql_read(sql)
table = teamResults(rows)
table.border = True
table.classes = ['table-striped', 'table-condensed', 'table-hover']
return render_template('_teamRecordResults.html', table=table)
else:
return 'Invalid search data entered'
@routes.route('/clubPlayingRecords')
def clubPlayingRecords():
sql = "SELECT hockeyClub FROM mensHockeyClubs ORDER BY hockeyClub"
sql2 = "SELECT nextClub, oppoLogo FROM hkfcDAdminSettings"
clubs = sql_read(sql)
settings = sql_read(sql2)
form = clubPlayingRecordsForm()
form.clubName.choices = [(name['hockeyClub'], name['hockeyClub']) for name in clubs]
clubLogo = settings[0]['oppoLogo']
return render_template('_clubPlayingRecords.html', data=clubs, selectedClubLogo=clubLogo, form=form)
@routes.route('/clubPlayingRecordSearch', methods=['POST'])
def clubPlayingRecordRearchResults():
_season = request.form['season']
_club = request.form['clubName']
if _club and request.method == 'POST':
sql = "SELECT * FROM _playerRecord_" + _club.lower() + " ORDER BY playerNumber"
sql2 = "SHOW COLUMNS FROM __playerRecord_" + _club.lower() + ""
rows = sql_read(sql)
columns = sql_read(sql2)
return render_template('_clubPlayingRecordResults.html', rows=rows, columns=columns)
else:
return 'Invalid search data entered'
@routes.route('/playerCheck')
def playerCheck():
sql = "SELECT hockeyClub FROM mensHockeyClubs ORDER BY hockeyClub"
sql2 = "SELECT nextClub, oppoLogo FROM hkfcDAdminSettings"
clubs = sql_read(sql)
settings = sql_read(sql2)
form = clubPlayingRecordsForm()
form.clubName.choices = [(name['hockeyClub'], name['hockeyClub']) for name in clubs]
clubLogo = settings[0]['oppoLogo']
return render_template('_playerCheck.html', data=clubs, selectedClubLogo=clubLogo, form=form)
@routes.route('/playerCheckResults', methods=['POST'])
def playerCheckResults():
_season = request.form['season']
_club = request.form['clubName']
players = []
if _club and request.method == 'POST':
sql = "SELECT * FROM _playerRecord_" + _club.lower() + " ORDER BY playerNumber"
sql2 = "SHOW COLUMNS FROM _playerRecord_" + _club.lower() + ""
rows = sql_read(sql)
columns = sql_read(sql2)
for row in rows:
has_played = 0
for column in columns:
if column['Field'].startswith("appearances"):
if row[column['Field']] > 0:
if has_played == 1:
players.append(row)
break
else:
has_played = 1
return render_template('_playerCheckResults.html', rows=players, columns=columns)
else:
return 'Invalid search data entered'