def country_page(key=None,operation=None,error=None): if request.method == 'GET': if request.args.get('operation') == 'delete': store = country_operations() result=store.delete_country(request.args.get('key')) return redirect(url_for('admin.country_page', error=result)) else: store = country_operations() countries=store.get_countries() now = datetime.datetime.now() error = request.args.get('error') return render_template('admin_countries.html', countries=countries, error=error, current_time=now.ctime()) else: if request.form['submit']=='cancel': return redirect(url_for('admin.country_page')) else: if request.form['key_value']=='': name = request.form['name'] country = Country(None,name, 0) store = country_operations() result=store.add_country(country) return redirect(url_for('admin.country_page', error=result)) else: name = request.form['name'] key = request.form['key_value'] store = country_operations() result=store.update_country(key, name) return redirect(url_for('admin.country_page', error=result))
def team_edit_page(key=None): store = team_operations() storeCourt = court_operations() storeCountry = country_operations() team = store.get_team(key) if key is not None else None courts = storeCourt.get_courts() countries = storeCountry.get_countries() now = datetime.datetime.now() return render_template('team_edit.html', team=team, courts=courts, countries=countries, current_time=now.ctime())
def coach_edit_page(key=None): store = coach_operations() storeTeam = team_operations() storeCountry = country_operations() storeGenders = gender_operations() coach = store.get_coach(key) if key is not None else None teams = storeTeam.get_teams() countries = storeCountry.get_countries() genders = storeGenders.get_genders() now = datetime.datetime.now() return render_template('coach_edit.html', coach=coach, teams=teams, countries=countries, genders=genders, current_time=now.ctime())
def player_edit_page(key=None): store = player_operations() storeCountry = country_operations() storeTeam = team_operations() storeGender = gender_operations() storePosition = position_operations() storeHand = hand_operations() player = store.get_player(key) if key is not None else None teams = storeTeam.get_teams() countries = storeCountry.get_countries() genders = storeGender.get_genders() positions = storePosition.get_positions() hands = storeHand.get_hands() now = datetime.datetime.now() return render_template('player_edit.html', player=player, teams=teams, countries=countries, genders=genders, positions=positions, hands=hands, current_time=now.ctime())
def get_team(self, key): global connection try: connection = dbapi2.connect(dsn) cursor = connection.cursor() statement = """SELECT objectid, name, shirtcolour, foundationdate, countryid, courtid FROM team where (objectid=%s and deleted=0)""" cursor.execute(statement, (key,)) id,name,color,date,countryid,courtid=cursor.fetchone() cursor.close() storeCountry = country_operations() storeCourt = court_operations() except dbapi2.DatabaseError: if connection: connection.rollback() finally: if connection: connection.close() return Team(id,name, color, date, countryid, storeCountry.get_country(countryid), courtid, storeCourt.get_court(courtid),0)
def get_teams(self): teams=[] global connection storeCountry = country_operations() storeCourt = court_operations() try: connection = dbapi2.connect(dsn) cursor = connection.cursor() statement = """SELECT team.objectid, team.name, team.shirtcolour, team.foundationdate, team.countryid,team.courtid FROM team WHERE team.deleted = 0 ORDER BY objectid """ cursor.execute(statement) teams = [(key, Team(key,name,color,date,countryid, storeCountry.get_country(countryid),courtid,storeCourt.get_court(courtid) , 0)) for key, name, color, date, countryid, courtid in cursor] cursor.close() except dbapi2.DatabaseError: if connection: connection.rollback() finally: if connection: connection.close() return teams
def get_coach(self, key): global connection storeCountry = country_operations() storeTeam = team_operations() storeGender = gender_operations() try: connection = dbapi2.connect(dsn) cursor = connection.cursor() statement = """SELECT objectid, name, surname, countryid, teamid, birthday, genderid FROM coach where (objectid=%s and deleted=0)""" cursor.execute(statement, (key,)) id,name,surname,countryid,teamid,birthyear,genderid=cursor.fetchone() cursor.close() except dbapi2.DatabaseError: if connection: connection.rollback() finally: if connection: connection.close() return Coach(id,name,surname,countryid, storeCountry.get_country(countryid), teamid, storeTeam.get_team(teamid), birthyear, genderid, storeGender.get_gender(genderid), 0)
def get_coaches(self): coachs=[] global connection storeCountry = country_operations() storeTeam = team_operations() storeGender = gender_operations() try: connection = dbapi2.connect(dsn) cursor = connection.cursor() statement = """SELECT coach.objectid, coach.name, coach.surname, coach.countryid, coach.teamid, coach.birthday, coach.genderid FROM coach WHERE coach.deleted = 0 ORDER BY objectid""" cursor.execute(statement) coachs = [(key, Coach(key,name,surname,countryid, storeCountry.get_country(countryid), teamid, storeTeam.get_team(teamid), birthyear, genderid, storeGender.get_gender(genderid), 0)) for key, name,surname, countryid, teamid, birthyear, genderid in cursor] cursor.close() except dbapi2.DatabaseError: if connection: connection.rollback() finally: if connection: connection.close() return coachs
def get_player(self, key): global connection storeCountry = country_operations() storeTeam = team_operations() storeGender = gender_operations() storePosition = position_operations() storeHand = hand_operations() try: connection = dbapi2.connect(dsn) cursor = connection.cursor() statement = """SELECT objectid,name, surname, birthdate, height, weight, startdate, teamid, countryid, genderid, positionid, handid, number FROM player WHERE (objectid=%s and deleted=0)""" cursor.execute(statement, (key,)) id,name,surname,birthdate,height,weight,startdate,teamid,countryid,genderid,positionid,handid,number=cursor.fetchone() cursor.close() except dbapi2.DatabaseError: if connection: connection.rollback() finally: if connection: connection.close() return Player(id, name, surname, birthdate, height, weight, startdate, teamid, storeTeam.get_team(teamid), countryid, storeCountry.get_country(countryid), genderid, storeGender.get_gender(genderid), positionid, storePosition.get_position(positionid), handid, storeHand.get_hand(handid), number, 0)
def get_players(self): players=[] global connection storeCountry = country_operations() storeTeam = team_operations() storeGender = gender_operations() storePosition = position_operations() storeHand = hand_operations() try: connection = dbapi2.connect(dsn) cursor = connection.cursor() statement = """SELECT objectid, name, surname, birthdate, height, weight, startdate, teamid, countryid, genderid, positionid, handid, number FROM player WHERE deleted = 0 ORDER BY objectid""" cursor.execute(statement) players = [(key, Player(key, name, surname, birthdate, height, weight, startdate, teamid, storeTeam.get_team(teamid),countryid, storeCountry.get_country(countryid), genderid, storeGender.get_gender(genderid), positionid, storePosition.get_position(positionid), handid, storeHand.get_hand(handid), number, 0)) for key, name, surname, birthdate, height, weight, startdate, teamid, countryid, genderid, positionid, handid, number in cursor] cursor.close() except dbapi2.DatabaseError: if connection: connection.rollback() finally: if connection: connection.close() return players
def country_edit_page(key=None): store = country_operations() country = store.get_country(key) if key is not None else None now = datetime.datetime.now() return render_template('country_edit.html', country=country, current_time=now.ctime())
def countries_page(): if request.method == 'GET': store = country_operations() countries=store.get_countries() now = datetime.datetime.now() return render_template('countries.html', countries=countries, current_time=now.ctime())