def stadiums(): connection, cursor = sql_connect() sql = 'SELECT id, name, country, total FROM stadiums' cursor = execute_sql(sql, connection, cursor) data = cursor.fetchall() stadiums = [] for stadium in data: stadiums.append({'id': stadium[0], 'name': stadium[1], 'country': stadium[2], 'total': stadium[3]}) return render_template("stadiums.html", stadiums=stadiums, isAuthenticated = user_is_authenticated())
def add_stadium(): if request.method == 'GET': return render_template('new_stadium.html', isAuthenticated = user_is_authenticated()) data = request.values.to_dict() if not 'name' in data.keys() or not 'country' in data.keys() or not 'total' in data.keys(): error = "Not all fields submitted" return render_template('new_stadium.html', error_msg=error, isAuthenticated = user_is_authenticated()) if not len(data['country']) == 2: return render_template('new_stadium.html', error_msg="Country code length should be 2", isAuthenticated = user_is_authenticated()) try: if int(data['total']) < 1: return render_template('new_stadium.html', error_msg="Capacity should be bigger than 0", isAuthenticated = user_is_authenticated()) except: return render_template('new_stadium.html', error_msg="Capacity should be integer number", isAuthenticated = user_is_authenticated()) connection, cursor = sql_connect() sql = "INSERT INTO stadiums (name, country, total) VALUES ('%s', '%s', %s)" % (data['name'], data['country'], data['total']) cursor = execute_sql(sql, connection, cursor) return redirect('/stadiums')
def player_add(): if UserSession.currentUser is None: return redirect('/') if request.method == 'POST': player = Player() player.firstName = request.form['player_firstName'] player.lastName = request.form['player_lastName'] player.birthday = request.form['player_birthday'] player.country = request.form['player_country'] player.height = request.form['player_height'] player = playerhandler.Insert(player) return redirect('/players') elif request.method == 'GET': return render_template('player_add.html', isAuthenticated = user_is_authenticated())
def career_add(key): if UserSession.currentUser is None: return redirect('/') if request.method == 'POST': career = Career() career.biography = request.form['career_biography'] career.olympicGames = request.form['career_olympicGames'] career.singlesHighestRanking = request.form['career_singles'] career.doublesHighestRanking = request.form['career_doubles'] career.playerId = request.form['career_playerId'] career = careerhandler.Insert(career) tempUrl = "/player/" + str(key) return redirect(tempUrl) elif request.method == 'GET': return render_template('/career_add.html', isAuthenticated = user_is_authenticated(), playerId = key)
def career_page(key): if request.method == 'GET': currentcareer = careerhandler.GetByPlayerID(key) currentcareer.playerId = key return render_template('/player_career.html', career=currentcareer, isAuthenticated = user_is_authenticated())
def leagues_page(): return render_template('leagues.html', isAuthenticated = user_is_authenticated())
def home(): if request.method == 'GET': now = datetime.datetime.now() if user_is_authenticated: return render_template('home.html', current_time=now.ctime(), isAuthenticated = user_is_authenticated()) else: return render_template('home.html', current_time=now.ctime(), isAuthenticated = user_is_authenticated())
def player_update(key): if UserSession.currentUser is None: return redirect('/') if request.method == 'POST': player = Player() player.playerId = key player.firstName = request.form['player_firstName'] player.lastName = request.form['player_lastName'] player.birthday = request.form['player_birthday'] player.country = request.form['player_country'] player.height = request.form['player_height'] player = playerhandler.Update(player) return redirect('/players') elif request.method == 'GET': current = playerhandler.GetByID(key) return render_template('player_update.html', currentPlayer=current, isAuthenticated = user_is_authenticated())
def player_page(key): if request.method == 'GET': currentplayer = playerhandler.GetByID(key) return render_template('/player.html', player=currentplayer, isAuthenticated = user_is_authenticated())
def players(): if request.method == 'GET': playerList = [] filterExpression = FilterExpression() playerList = playerhandler.Get(filterExpression) return render_template('players.html', playerList = playerList, isAuthenticated = user_is_authenticated())