def edit_player(): """Edit an existing player name""" players = FOOSBALL_DATA.get_all_players() data_manager.LOGGER.info(flask.request.method) if flask.request.method == 'POST': data_manager.LOGGER.info(flask.request.form) previous_player = flask.request.form['previous_player'].encode('utf-8') first_quote = previous_player.find('"') second_quote = previous_player.find('"', first_quote + 1) previous_player = (previous_player[:first_quote - 1], previous_player[second_quote + 2:], previous_player[first_quote + 1:second_quote]) # first_name = flask.request.form['first_name'].encode('utf-8') # last_name = flask.request.form['last_name'].encode('utf-8') # nickname = flask.request.form['nickname'].encode('utf-8') previous_player = { 'previous_first_name': previous_player[0], 'previous_last_name': previous_player[1], 'previous_nickname': previous_player[2] } new = { 'first_name': flask.request.form['first_name'].encode('utf-8'), 'last_name': flask.request.form['last_name'].encode('utf-8'), 'nickname': flask.request.form['nickname'].encode('utf-8') } #new = (first_name, last_name, nickname) data_manager.LOGGER.info(previous_player) data_manager.LOGGER.info(new) try: FOOSBALL_DATA.edit_player(previous_player, new) FOOSBALL_DATA.commit_data() except data_manager_exceptions.DBValueError as error: data_manager.LOGGER.error(error.msg) return flask.render_template('editplayer.html', error=error) except data_manager_exceptions.DBSyntaxError as error: data_manager.LOGGER.error(error.msg) return flask.render_template('editplayer.html', error=error) except data_manager_exceptions.DBConnectionError as error: data_manager.LOGGER.error(error.msg) return flask.render_template('editplayer.html', error=error) except data_manager_exceptions.DBExistError as error: data_manager.LOGGER.error(error.msg) return flask.render_template('editplayer.html', error=error) else: pass message = 'Player successfully edited' players = FOOSBALL_DATA.get_all_players() return flask.render_template('editplayer.html', message=message, players=players) elif flask.request.method == 'GET': return flask.render_template('editplayer.html', players=players) else: raise foosball_exceptions.HTTPError( "Received unrecognized HTTP method")
def add_player(): """Add Player webpage Args: first_name (str): player first name last_name (str): player last name nickname (str): player nickname Returns: display add player display player Raises: foosball_exceptions.HTTPError """ if flask.request.method == 'POST': first_name = flask.request.form['first_name'].encode('utf-8') last_name = flask.request.form['last_name'].encode('utf-8') nickname = flask.request.form['nickname'].encode('utf-8') try: FOOSBALL_DATA.add_player(first_name=first_name, last_name=last_name, nickname=nickname) FOOSBALL_DATA.commit_data() except data_manager_exceptions.DBValueError as error: data_manager.LOGGER.error(error.msg) return flask.render_template('addplayer.html', error=error) except data_manager_exceptions.DBSyntaxError as error: data_manager.LOGGER.error(error.msg) return flask.render_template('addplayer.html', error=error) except data_manager_exceptions.DBConnectionError as error: data_manager.LOGGER.error(error.msg) return flask.render_template('addplayer.html', error=error) except data_manager_exceptions.DBExistError as error: data_manager.LOGGER.error(error.msg) return flask.render_template('addplayer.html', error=error) else: pass message = 'Player successfully added' players = FOOSBALL_DATA.get_all_players() return flask.render_template('player.html', message=message, players=players) elif flask.request.method == 'GET': return flask.render_template('addplayer.html') else: raise foosball_exceptions.HTTPError( "Received unrecognized HTTP method")
def player_stat(): """Player Stat webpage Args: None Returns: display dashboard """ players = FOOSBALL_DATA.get_all_players() results = FOOSBALL_DATA.get_all_results() if flask.request.method == 'POST': selected_player = flask.request.form['player'].encode('utf-8') selected_position = flask.request.form['position'].encode('utf-8') first_quote = selected_player.find('"') second_quote = selected_player.find('"', first_quote + 1) final_player = (selected_player[:first_quote - 1], selected_player[second_quote + 2:], selected_player[first_quote + 1:second_quote]) try: individual_results = FOOSBALL_DATA.get_individual_results( player=final_player, position=selected_position) except data_manager_exceptions.DBValueError as error: LOGGER.error(error.msg) return flask.render_template('playerstat.html', error=error, players=players, results=results) except data_manager_exceptions.DBSyntaxError as error: LOGGER.error(error.msg) return flask.render_template('playerstat.html', error=error, players=players, results=results) except data_manager_exceptions.DBConnectionError as error: LOGGER.error(error.msg) return flask.render_template('playerstat.html', error=error, players=players, results=results) except data_manager_exceptions.DBExistError as error: LOGGER.error(error.msg) return flask.render_template('playerstat.html', error=error, players=players, results=results) else: pass return flask.render_template('playerstat.html', results=individual_results, players=players) elif flask.request.method == 'GET': return flask.render_template('playerstat.html', results=results, players=players) else: raise foosball_exceptions.HTTPError( "Received unrecognized HTTP method")
def add_result(): """Add Result webpage Args: offense_winner(tup): offense_winner defense_winner (tup): defense_winner offense_loser (tup): offense_loser defense_loser (tup): defense_loser Returns: display add result display result Raises: foosball_exceptions.HTTPError """ players = FOOSBALL_DATA.get_all_players() if flask.request.method == 'POST': offense_winner = flask.request.form['offense_winner'].encode('utf-8') offense_loser = flask.request.form['offense_loser'].encode('utf-8') defense_winner = flask.request.form['defense_winner'].encode('utf-8') defense_loser = flask.request.form['defense_loser'].encode('utf-8') first_quote = offense_winner.find('"') second_quote = offense_winner.find('"', first_quote + 1) final_offense_winner = (offense_winner[:first_quote - 1], offense_winner[second_quote + 2:], offense_winner[first_quote + 1:second_quote]) first_quote = offense_loser.find('"') second_quote = offense_loser.find('"', first_quote + 1) final_offense_loser = (offense_loser[:first_quote - 1], offense_loser[second_quote + 2:], offense_loser[first_quote + 1:second_quote]) first_quote = defense_winner.find('"') second_quote = defense_winner.find('"', first_quote + 1) final_defense_winner = (defense_winner[:first_quote - 1], defense_winner[second_quote + 2:], defense_winner[first_quote + 1:second_quote]) first_quote = defense_loser.find('"') second_quote = defense_loser.find('"', first_quote + 1) final_defense_loser = (defense_loser[:first_quote - 1], defense_loser[second_quote + 2:], defense_loser[first_quote + 1:second_quote]) try: FOOSBALL_DATA.add_result(offense_winner=final_offense_winner, defense_winner=final_defense_winner, offense_loser=final_offense_loser, defense_loser=final_defense_loser) FOOSBALL_DATA.commit_data() except data_manager_exceptions.DBValueError as error: data_manager.LOGGER.error(error.msg) return flask.render_template('addresult.html', error=error, players=players) except data_manager_exceptions.DBSyntaxError as error: data_manager.LOGGER.error(error.msg) return flask.render_template('addresult.html', error=error, players=players) except data_manager_exceptions.DBConnectionError as error: data_manager.LOGGER.error(error.msg) return flask.render_template('addresult.html', error=error, players=players) except data_manager_exceptions.DBExistError as error: data_manager.LOGGER.error(error.msg) return flask.render_template('addresult.html', error=error, players=players) else: pass message = 'Result successfully added' results = FOOSBALL_DATA.get_all_results() return flask.render_template('result.html', message=message, results=results) elif flask.request.method == 'GET': return flask.render_template('addresult.html', players=players) else: raise foosball_exceptions.HTTPError( "Received unrecognized HTTP method")
def add_team(): """Add Team webpage Args: team_name (str): team name member_one (tup): first team member member_two (tup): second team member Returns: display add team display team Raises: foosball_exceptions.HTTPError """ players = FOOSBALL_DATA.get_all_players() if flask.request.method == 'POST': team_name = flask.request.form['team_name'].encode('utf-8') member_one = flask.request.form['member_one'].encode('utf-8') member_two = flask.request.form['member_two'].encode('utf-8') first_quote = member_one.find('"') second_quote = member_one.find('"', first_quote + 1) final_member_one = (member_one[:first_quote - 1], member_one[second_quote + 2:], member_one[first_quote + 1:second_quote]) first_quote = member_two.find('"') second_quote = member_two.find('"', first_quote + 1) final_member_two = (member_two[:first_quote - 1], member_two[second_quote + 2:], member_two[first_quote + 1:second_quote]) try: FOOSBALL_DATA.add_team(team_name=team_name, member_one=final_member_one, member_two=final_member_two) FOOSBALL_DATA.commit_data() except data_manager_exceptions.DBValueError as error: data_manager.LOGGER.error(error.msg) return flask.render_template('addteam.html', error=error, players=players) except data_manager_exceptions.DBSyntaxError as error: data_manager.LOGGER.error(error.msg) return flask.render_template('addteam.html', error=error, players=players) except data_manager_exceptions.DBConnectionError as error: data_manager.LOGGER.error(error.msg) return flask.render_template('addteam.html', error=error, players=players) except data_manager_exceptions.DBExistError as error: data_manager.LOGGER.error(error.msg) return flask.render_template('addteam.html', error=error, players=players) else: pass message = 'Team successfully added' teams = FOOSBALL_DATA.get_all_teams() return flask.render_template('team.html', message=message, teams=teams) elif flask.request.method == 'GET': return flask.render_template('addteam.html', players=players) else: raise foosball_exceptions.HTTPError( "Received unrecognized HTTP method")