Namespace enumeration code
This commit is contained in:
parent
c23adae71a
commit
456f3b58eb
117
forms.py
117
forms.py
@ -1,5 +1,3 @@
|
|||||||
#import MySQLdb
|
|
||||||
import pymysql
|
|
||||||
import os
|
import os
|
||||||
from app import app
|
from app import app
|
||||||
from flask_wtf import FlaskForm
|
from flask_wtf import FlaskForm
|
||||||
@ -10,117 +8,10 @@ from wtforms import validators, ValidationError
|
|||||||
from wtforms.validators import InputRequired, Email, Length
|
from wtforms.validators import InputRequired, Email, Length
|
||||||
from readSettings import mySettings
|
from readSettings import mySettings
|
||||||
from flask_bootstrap import Bootstrap
|
from flask_bootstrap import Bootstrap
|
||||||
from datetime import datetime
|
|
||||||
#from dbWrite import read_cloudsql, sql_read, sql_read_static
|
|
||||||
|
|
||||||
|
|
||||||
class LoginForm(FlaskForm):
|
class deploySelectForm(FlaskForm):
|
||||||
username = StringField('username', validators=[InputRequired(), Length(min=4, max=15)])
|
namespace = SelectField('namespace', validators=[InputRequired(), Length(min=4, max=15)])
|
||||||
password = PasswordField('password', validators=[InputRequired(), Length(min=4, max=80)])
|
deployment = SelectField('password', validators=[InputRequired(), Length(min=4, max=80)])
|
||||||
remember = BooleanField('remember me')
|
version = SelectField('remember me')
|
||||||
|
|
||||||
class RegisterForm(FlaskForm):
|
|
||||||
email = StringField('email', validators=[InputRequired(), Email(message='Invalid email'), Length(max=50)])
|
|
||||||
username = StringField('username', validators=[InputRequired(), Length(min=4, max=15)])
|
|
||||||
password = PasswordField('password', validators=[InputRequired(), Length(min=8, max=80)])
|
|
||||||
|
|
||||||
class addPlayerForm(FlaskForm):
|
|
||||||
playerClub = SelectField('Club:', choices=[])
|
|
||||||
playerTeam = SelectField('Team:', choices=[])
|
|
||||||
playerForenames = TextField('Forenames:')
|
|
||||||
playerSurnames = TextField('Surname:')
|
|
||||||
playerNickname = TextField('Nickname')
|
|
||||||
playerChineseName = TextField('Chinese Name:')
|
|
||||||
playerEmailAddress = TextField('Email Address:')
|
|
||||||
playerDob = DateField('Date of Birth:', default=datetime.today, format='%Y-%m-%d')
|
|
||||||
playerHkid = TextField('HKID Number:')
|
|
||||||
playerNumber = TextField('Shirt Number:')
|
|
||||||
playerTelNumber = TextField('Player Contact Number:')
|
|
||||||
submit = SubmitField('Submit')
|
|
||||||
|
|
||||||
class addTeamForm(FlaskForm):
|
|
||||||
clubName = SelectField("Club of team entry to create", coerce=str)
|
|
||||||
teamName = TextField("Team table to create (e.g. A, B, C, etc.)", validators=[InputRequired(), Length(max=1)])
|
|
||||||
submit = SubmitField("Submit")
|
|
||||||
|
|
||||||
class addClubForm(FlaskForm):
|
|
||||||
clubName = TextField("Name of the Hockey Club to add")
|
|
||||||
submit = SubmitField("Submit")
|
|
||||||
|
|
||||||
class playerDbCreateForm(FlaskForm):
|
|
||||||
clubName = SelectField("Name of the Hockey Club to create player database for")
|
|
||||||
year = SelectField("Season start year")
|
|
||||||
submit = SubmitField("Submit")
|
|
||||||
|
|
||||||
class searchForm(FlaskForm):
|
|
||||||
seasonStart = datetime.strptime('2018-09-01', '%Y-%m-%d')
|
|
||||||
season = SelectField('Season data to search', choices=[('2019', '2019/20'), ('2018', '2018/19'), ('2017', '2017/18'), ('2016', '2016/17'), ('2015', '2015/16'), ('2014', '2014/15'), ('2013', '2013/14')])
|
|
||||||
clubName = SelectField("Club to search", choices=[], coerce=str)
|
|
||||||
teamName = SelectField("Select a Team", choices=[])
|
|
||||||
startDate = DateField('DatePicker', format='%Y-%m-%d', default=seasonStart)
|
|
||||||
endDate = DateField('DatePicker', format='%Y-%m-%d', default=datetime.today())
|
|
||||||
submitButton = SubmitField("Submit")
|
|
||||||
|
|
||||||
class playerRecordsForm(FlaskForm):
|
|
||||||
season = SelectField('Season data to search', choices=[('2019', '2019/20'), ('2018', '2018/19'), ('2017', '2017/18'), ('2016', '2016/17'), ('2015', '2015/16'), ('2014', '2014/15'), ('2013', '2013/14')])
|
|
||||||
clubName = SelectField("Club to search", choices=[], coerce=str)
|
|
||||||
teamName = SelectField("Select a Team", choices=[])
|
|
||||||
submitButton = SubmitField("Submit")
|
|
||||||
|
|
||||||
class teamRecordsForm(FlaskForm):
|
|
||||||
season = SelectField('Season data to search', choices=[('2019', '2019/20'), ('2018', '2018/19'), ('2017', '2017/18'), ('2016', '2016/17'), ('2015', '2015/16'), ('2014', '2014/15'), ('2013', '2013/14')])
|
|
||||||
clubName = SelectField("Club to search", choices=[], coerce=str)
|
|
||||||
teamName = SelectField("Select a Team", choices=[])
|
|
||||||
submitButton = SubmitField("Submit")
|
|
||||||
|
|
||||||
class clubPlayingRecordsForm(FlaskForm):
|
|
||||||
season = SelectField('Season data to search', choices=[('2019', '2019/20'), ('2018', '2018/19'), ('2017', '2017/18'), ('2016', '2016/17'), ('2015', '2015/16'), ('2014', '2014/15'), ('2013', '2013/14')])
|
|
||||||
clubName = SelectField("Club to search", choices=[], coerce=str)
|
|
||||||
submitButton = SubmitField("Submit")
|
|
||||||
|
|
||||||
class motmForm(FlaskForm):
|
|
||||||
startDate = DateField('DatePicker', format='%d-%m-%Y')
|
|
||||||
endDate = DateField('DatePicker', format='%d-%m-%Y')
|
|
||||||
|
|
||||||
class motmAdminForm(FlaskForm):
|
|
||||||
startDate = DateField('DatePicker', format='%d-%m-%Y')
|
|
||||||
endDate = DateField('DatePicker', format='%d-%m-%Y')
|
|
||||||
|
|
||||||
class squadListForm(FlaskForm):
|
|
||||||
teamName = SelectField("HKFC team to display")
|
|
||||||
submit = SubmitField("Submit")
|
|
||||||
|
|
||||||
class adminSettingsForm(FlaskForm):
|
|
||||||
nextOppoClub = SelectField('Next Opposition Club:', choices=[], default=mySettings('club'))
|
|
||||||
nextOppoTeam = SelectField("Next Opposition Team:", choices=[])
|
|
||||||
nextMatchDate = DateField('DatePicker', format='%Y-%m-%d', default=mySettings('date'))
|
|
||||||
currMotM = SelectField('Current Man of the Match:', choices=[], default=mySettings('motm'))
|
|
||||||
currDotD = SelectField('Current Dick of the Day:', choices=[], default=mySettings('dotd'))
|
|
||||||
saveButton = SubmitField('Save Settings')
|
|
||||||
activateButton = SubmitField('Activate MotM Vote')
|
|
||||||
|
|
||||||
class goalsAssistsForm(FlaskForm):
|
|
||||||
fixtureNumber = TextField('Fixture Number')
|
|
||||||
match = SelectField('Fixture')
|
|
||||||
homeTeam = TextField('Home Team')
|
|
||||||
awayTeam = TextField('Away Team')
|
|
||||||
playerNumber = TextField('Player Number')
|
|
||||||
playerName = TextField('Player Name')
|
|
||||||
assists = SelectField('Assists:', choices=[(0, '0'), (1, '1'), (2, '2'), (3, '3'), (4, '4')])
|
|
||||||
goals = SelectField('Goals:', choices=[(0, '0'), (1, '1'), (2, '2'), (3, '3'), (4, '4')])
|
|
||||||
submit = SubmitField('Submit')
|
|
||||||
# def __init__(self, *args, **kwargs):
|
|
||||||
# super(goalsAssistsForm, self).__init__(*args, **kwargs)
|
|
||||||
# read_only(self.homeTeam)
|
|
||||||
# read_only(self.awayTeam)
|
|
||||||
|
|
||||||
|
|
||||||
class adminSettingsForm2(FlaskForm):
|
|
||||||
nextMatch = SelectField('Fixture', choices=[], default=mySettings('match'))
|
|
||||||
nextOppoClub = TextField('Next Opposition Club:', default=mySettings('club'))
|
|
||||||
nextOppoTeam = TextField("Next Opposition Team:")
|
|
||||||
currMotM = SelectField('Current Man of the Match:', choices=[], default=mySettings('motm'))
|
|
||||||
currDotD = SelectField('Current Dick of the Day:', choices=[], default=mySettings('dotd'))
|
|
||||||
saveButton = SubmitField('Save Settings')
|
|
||||||
activateButton = SubmitField('Activate MotM Vote')
|
|
||||||
|
|
||||||
|
|||||||
71
main.py
71
main.py
@ -1,11 +1,7 @@
|
|||||||
# encoding=utf-8
|
# encoding=utf-8
|
||||||
|
|
||||||
import pymysql
|
|
||||||
#import MySQLdb
|
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
import hashlib, uuid
|
|
||||||
|
|
||||||
from app import app
|
from app import app
|
||||||
from flask import Flask, flash, render_template, request, redirect, url_for
|
from flask import Flask, flash, render_template, request, redirect, url_for
|
||||||
from flask_wtf import FlaskForm
|
from flask_wtf import FlaskForm
|
||||||
@ -13,59 +9,34 @@ from flask_bootstrap import Bootstrap
|
|||||||
from wtforms import StringField, PasswordField, BooleanField
|
from wtforms import StringField, PasswordField, BooleanField
|
||||||
from wtforms.fields.html5 import DateField
|
from wtforms.fields.html5 import DateField
|
||||||
from wtforms.validators import InputRequired, Email, Length
|
from wtforms.validators import InputRequired, Email, Length
|
||||||
from forms import LoginForm, RegisterForm
|
|
||||||
from dbWrite import sql_write, sql_write_static, sql_read, sql_read_static
|
|
||||||
from routes import *
|
from routes import *
|
||||||
|
from logging import error, info
|
||||||
|
from subprocess import STDOUT, CalledProcessError, check_output
|
||||||
|
from itertools import islice
|
||||||
|
import json
|
||||||
|
|
||||||
app.register_blueprint(routes)
|
def get_namespaces():
|
||||||
|
command = "/usr/local/bin/kubectl get ns -ojson"
|
||||||
|
info(f"Running command: {command}")
|
||||||
|
try:
|
||||||
|
output = check_output(command.split(" "), stderr=STDOUT).decode("utf-8")
|
||||||
|
except CalledProcessError as err:
|
||||||
|
error(err.output.decode("utf-8"))
|
||||||
|
raise err
|
||||||
|
info(f"Output from command:\n{output}")
|
||||||
|
data = json.loads(output)
|
||||||
|
return data
|
||||||
|
|
||||||
|
@app.route('/', methods=['GET', 'POST'])
|
||||||
@app.route('/hkfc-d/vote-chart', methods=['GET', 'POST'])
|
def namespacesForm():
|
||||||
def hkfc_d_vote_chart():
|
form = deploySelectForm()
|
||||||
form = LoginForm()
|
namespaces = get_namespaces()
|
||||||
print('Here we are')
|
print('Here we are')
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
sql = "SELECT username FROM hockeyUsers WHERE (username= '" + form.username.data + "')"
|
return redirect(url_for('/'))
|
||||||
print(sql)
|
|
||||||
rows = sql_read(sql)
|
|
||||||
print(rows)
|
|
||||||
return redirect(url_for('/hkfc-d/voting'))
|
|
||||||
# return '<h1>Something went wrong there</h1>'
|
# return '<h1>Something went wrong there</h1>'
|
||||||
|
|
||||||
return render_template('hkfc-d/login-vote.html', form=form)
|
return render_template('index.html', namespaces=namespaces, form=form)
|
||||||
|
|
||||||
@app.route('/login', methods=['GET', 'POST'])
|
|
||||||
def login():
|
|
||||||
form = LoginForm()
|
|
||||||
print('Here we are')
|
|
||||||
if form.validate_on_submit():
|
|
||||||
sql = "SELECT username FROM hockeyUsers WHERE (username= '" + form.username.data + "')"
|
|
||||||
print(sql)
|
|
||||||
rows = sql_write(sql)
|
|
||||||
print(rows)
|
|
||||||
print(rows[0])
|
|
||||||
return redirect(url_for('/hkfc-d/voting'))
|
|
||||||
else:
|
|
||||||
return 'Something went wrong'
|
|
||||||
# return '<h1>Something went wrong there</h1>'
|
|
||||||
return render_template('login.html', form=form)
|
|
||||||
|
|
||||||
@app.route('/register', methods=['GET', 'POST'])
|
|
||||||
def register():
|
|
||||||
form = RegisterForm()
|
|
||||||
if form.validate_on_submit():
|
|
||||||
salt = uuid.uuid4().hex
|
|
||||||
hashed_password = hashlib.sha512(form.password.data + salt).hexdigest()
|
|
||||||
|
|
||||||
sql = "INSERT INTO hockeyUsers (username, email, password) VALUES ('" + form.username.data + "', '" + form.email.data + "', '" + hashed_password + "')"
|
|
||||||
print(sql)
|
|
||||||
db = write_cloudsql()
|
|
||||||
cursor = db.cursor()
|
|
||||||
cursor.execute(sql)
|
|
||||||
db.commit()
|
|
||||||
return '<h2>New user has been created!</h2>'
|
|
||||||
|
|
||||||
return render_template('register.html', form=form)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run(host='0.0.0.0', port=3000, debug=True)
|
app.run(host='0.0.0.0', port=3000, debug=True)
|
||||||
|
|||||||
@ -1,24 +1,24 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Team Season Results Search *TESTING*</title>
|
<title>Deployment Selection *TESTING*</title>
|
||||||
<link rel="stylesheet" media="screen" href ="/static/css/bootstrap.min.css">
|
<link rel="stylesheet" media="screen" href ="/static/css/bootstrap.min.css">
|
||||||
<link rel="stylesheet" href="/static/css/bootstrap-theme.min.css">
|
<link rel="stylesheet" href="/static/css/bootstrap-theme.min.css">
|
||||||
<meta name="viewport" content = "width=device-width, initial-scale=1.0">
|
<meta name="viewport" content = "width=device-width, initial-scale=1.0">
|
||||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
|
||||||
<script src="/static/js/bootstrap.min.js"></script>
|
<script src="/static/js/bootstrap.min.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<h2>Search Parameters - select both a club and team</h2>
|
<h2>Select a namespace and a deployment</h2>
|
||||||
<body onload="myFunction()">
|
<body onload="myFunction()">
|
||||||
<dl>
|
<dl>
|
||||||
<p>
|
<p>
|
||||||
{{ form.csrf_token }}
|
{{ form.csrf_token }}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xs-12">
|
<div class="col-xs-12">
|
||||||
<form class="col-sm-6" method="post" action="/searchTeam">
|
<form class="col-sm-6" method="post" action="/get_namespace">
|
||||||
<div class = "row">
|
<div class = "row">
|
||||||
<div class = "col-sm-6">
|
<div class = "col-sm-6">
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<span class="input-group-addon" id="basic-addon1">Season data to search:</span>
|
<span class="input-group-addon" id="basic-addon1">Namespace:</span>
|
||||||
{{ form.season(class_="form-control") }}
|
{{ form.season(class_="form-control") }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -26,39 +26,15 @@
|
|||||||
<div class = "row">
|
<div class = "row">
|
||||||
<div class = "col-sm-6">
|
<div class = "col-sm-6">
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<span class="input-group-addon" id="basic-addon2">Club:</span>
|
<span class="input-group-addon" id="basic-addon2">Deployment:</span>
|
||||||
{{ form.clubName(class_="form-control") }}
|
{{ form.clubName(class_="form-control") }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class = "col-sm-4">
|
|
||||||
<div class="input-group">
|
|
||||||
<span class="input-group-addon" id="basic-addon3">Team:</span>
|
|
||||||
{{ form.teamName(class_="form-control") }}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class = "row">
|
|
||||||
<div class = "col-sm-6">
|
|
||||||
<div class="input-group">
|
|
||||||
<span class="input-group-addon" id="basic-addon4">Start Date:</span>
|
|
||||||
{{ form.startDate(class_="form-control") }}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class = "col-sm-4">
|
|
||||||
<div class="input-group">
|
|
||||||
<span class="input-group-addon" id="basic-addon5">End Date:</span>
|
|
||||||
{{ form.endDate(class_="form-control") }}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<p>
|
<p>
|
||||||
{{ form.submitButton(class_="btn btn-success") }}
|
{{ form.submitButton(class_="btn btn-success") }}
|
||||||
<a class="btn btn-danger" href="/dashboard" role="button">Cancel</a>
|
<a class="btn btn-danger" href="/" role="button">Cancel</a>
|
||||||
</p>
|
</p>
|
||||||
</form>
|
</form>
|
||||||
<div class="col-sm-0">
|
|
||||||
<img src="{{ selectedClubLogo }}" height="120" id="selectedClubLogo"/>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</p>
|
</p>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user