moving SQL statements to top of defs
This commit is contained in:
parent
0628289681
commit
0ad23e9be4
28
main.py
28
main.py
@ -23,48 +23,36 @@ app.register_blueprint(routes)
|
||||
@app.route('/hkfc-d/vote-chart', methods=['GET', 'POST'])
|
||||
def hkfc_d_vote_chart():
|
||||
form = LoginForm()
|
||||
print('Here we are')
|
||||
user_lookup = "SELECT username FROM hockeyUsers WHERE (username= '" + form.username.data + "')"
|
||||
if form.validate_on_submit():
|
||||
sql = "SELECT username FROM hockeyUsers WHERE (username= '" + form.username.data + "')"
|
||||
print(sql)
|
||||
rows = sql_read(sql)
|
||||
print(rows)
|
||||
rows = sql_read(user_lookup)
|
||||
return redirect(url_for('/hkfc-d/voting'))
|
||||
# return '<h1>Something went wrong there</h1>'
|
||||
|
||||
return render_template('hkfc-d/login-vote.html', form=form)
|
||||
else:
|
||||
return render_template('hkfc-d/login-vote.html', form=form)
|
||||
|
||||
@app.route('/login', methods=['GET', 'POST'])
|
||||
def login():
|
||||
form = LoginForm()
|
||||
print('Here we are')
|
||||
user_lookup = "SELECT username FROM hockeyUsers WHERE (username= '" + form.username.data + "')"
|
||||
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])
|
||||
rows = sql_write(user_lookup)
|
||||
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()
|
||||
user_create = "INSERT INTO hockeyUsers (username, email, password) VALUES ('" + form.username.data + "', '" + form.email.data + "', '" + hashed_password + "')"
|
||||
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)
|
||||
cursor.execute(user_create)
|
||||
db.commit()
|
||||
return '<h2>New user has been created!</h2>'
|
||||
|
||||
return render_template('register.html', form=form)
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@ -18,9 +18,8 @@ basic_auth = BasicAuth(app)
|
||||
|
||||
@routes.route('/convenor/clubList')
|
||||
def convenorListClub():
|
||||
sql = "SELECT club, team, league from _clubTeams ORDER BY club, team"
|
||||
rows = sql_read(sql)
|
||||
print(rows)
|
||||
clubTeam_lookup = "SELECT club, team, league from _clubTeams ORDER BY club, team"
|
||||
rows = sql_read(clubTeam_lookup)
|
||||
table = clubList(rows)
|
||||
table.border = True
|
||||
table.classes = ['table-striped', 'table-condensed', 'table-hover']
|
||||
@ -34,22 +33,21 @@ def convenorAddClub():
|
||||
|
||||
@routes.route('/convenor/clubAddResult', methods=['POST'])
|
||||
def convenorAddClubResult():
|
||||
club_lookup = "SELECT club FROM _clubTeams WHERE club='" + _club + "' GROUP BY club"
|
||||
club_create = "INSERT INTO _clubTeams (club, team) VALUES ('" + _club + "', 'A')"
|
||||
try:
|
||||
_club = request.form['clubName']
|
||||
# validate that this data has been entered
|
||||
if _club and request.method == 'POST':
|
||||
sql = "SELECT club FROM _clubTeams WHERE club='" + _club + "' GROUP BY club"
|
||||
clubExist = sql_read(sql)
|
||||
clubExist = sql_read(club_lookup)
|
||||
if clubExist:
|
||||
return 'Club already exists - try adding a team instead'
|
||||
else:
|
||||
sql2 = "INSERT INTO _clubTeams (club, team) VALUES ('" + _club + "', 'A')"
|
||||
sql_write(sql2)
|
||||
sql_write(club_create)
|
||||
return render_template('_convenorClubAddResults.html', data=_club)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
|
||||
@routes.route('/convenor/teamAdd')
|
||||
def convenorAddTeam():
|
||||
sql = "SELECT club FROM _clubTeams GROUP BY club ORDER BY club"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user