Parts Implemented by Muhammed Yusuf Temiz¶
Models¶
final4.models.coach¶
Coach class and Database connection handlers¶
-
class
final4.models.coach.Coach(name, surname, country_id, country=None, _id=None)¶ Coach object
-
getAttrs()¶ returns attributes of the Coach object as a dictionary. Keys are taken from the coachtable and corresponding values are taken from the Coach object attributes.
Returns: attributes of the Coach object as a dictionary. Return type: dict
-
img_path(_id=None)¶ returns the url of the image of the coach. The image url generated based on _id value.
Returns: image url Return type: string
-
-
class
final4.models.coach.Coaches(conn, cur)¶ the Coaches object provides functions for database connections of coaches table.
Parameters: - conn – psycopg2 connection object
- cur – psycopg2 cursor object
-
add_coach(coach)¶ inserts a new row to the coaches table with values of the given coach attributes.
Parameters: coach – new Coach object
-
delete_coach(_id)¶ deletes the row from the coaches table whose id is given _id.
Parameters: _id – id of the row - int
-
get_coach(_id)¶ Returns
final4.models.coach.Coachobject with values from the coaches table IF there is a record has a given _id ELSE returns None.Parameters: _id – id of the row - int Returns: coach or None Return type: final4.models.coach.Coachobject or None
-
get_coaches(limit=100, offset=0)¶ Returns result list and total number of results. Returning list is list of
final4.models.coach.Coachobject. All objects filled up with values from the rows of the coaches table. Also returns the total number of the result.Parameters: - limit – maximum number of the result
- offset – skip beginning of the result
Returns: coachlist, total
Return type: list, int
-
get_coaches_by(attrib, search_key, limit=100, offset=0)¶ Returns result list and total number of result. Returning list is list of
final4.models.coach.Coachobject. All objects filled up with values from the rows of the coaches table.The return list made up by filtered results with given parameters.
Parameters: - limit – maximum number of the result
- offset – skip beginning of the result
Returns: coachlist, total
Return type: list, int
-
get_coaches_search_by(attrib, search_key, limit=100, offset=0)¶ Returns result list and total number of result. Returning list is list of
final4.models.coach.Coachobject. All objects filled up with values from the rows of the coaches table.The return list made up by filtered results with given parameters.
Parameters: - limit – maximum number of the result
- offset – skip beginning of the result
Returns: coachlist, total
Return type: list, int
-
update_coach(_id, new)¶ Updates the row from the coaches table whose id is given _id. The new values is taken from given new Coach object.
Parameters: - _id – id of the row - int
- new – Coach object with new values
-
final4.models.coach.coachtable= ['id', 'name', 'surname', 'country_id', 'country']¶ corresponding key values of the League class attributes
final4.models.country¶
Country class and Database connection handlers¶
-
class
final4.models.country.Countries(conn, cur)¶ the Countries object provides functions for database connections of countries table.
Parameters: - conn – psycopg2 connection object
- cur – psycopg2 cursor object
-
add_country(country)¶ inserts a new row to the countries table with values of the given country attributes.
Parameters: country – new Country object
-
delete_country(_id)¶ deletes the row from the countries table whose id is given _id.
Parameters: _id – id of the row - int
-
get_countries(limit=100, offset=0)¶ Returns result list and total number of results. Returning list is list of
final4.models.country.Countryobject. All objects filled up with values from the rows of the countries table. Also returns the total number of the result.Parameters: - limit – maximum number of the result
- offset – skip beginning of the result
Returns: countrylist, total
Return type: list, int
-
get_countries_by(attrib, key, limit=100, offset=0)¶ Returns result list and total number of result. Returning list is list of
final4.models.country.Countryobject. All objects filled up with values from the rows of the countries table.The return list made up by filtered results with given parameters.
Parameters: - limit – maximum number of the result
- offset – skip beginning of the result
Returns: countrylist, total
Return type: list, int
-
get_country(_id)¶ Returns
final4.models.country.Countryobject with values from the countries table IF there is a record has a given _id ELSE returns None.Parameters: _id – id of the row - int Returns: country or None Return type: final4.models.country.Countryobject or None
-
get_country_name(name)¶ Returns
final4.models.country.Countryobject with values from the countries table IF there is a record has a given name ELSE returns None.Parameters: name – country name - int Returns: country or None Return type: final4.models.country.Countryobject or None
-
update_country(_id, new)¶ Updates the row from the countries table whose id is given _id. The new values is taken from given new Country object.
Parameters: - _id – id of the row - int
- new – Country object with new values
-
class
final4.models.country.Country(name, code, _id=None)¶ Country Object
flagpath is url for country flag. The filename generated based on country code.
Parameters: - name – country name
- code – ISO alpha-2 code
-
getAttrs()¶ returns attributes of the Country class as a dictionary. Keys are taken from the countrytable and corresponding values are taken from the Country object attributes.
Returns: attributes of the Country object as a dictionary. Return type: dict
final4.models.league¶
League class and Database connection handlers¶
-
class
final4.models.league.League(name, country_id, country=None, _id=None)¶ League object
-
getAttrs()¶ returns attributes of the League class as a dictionary. Keys are taken from the leaguetable and corresponding values are taken from the League object attributes.
Returns: attributes of the League object as a dictionary. Return type: dict
-
-
class
final4.models.league.Leagues(conn, cur)¶ the Leagues object provides functions for database connections of leagues table.
Parameters: - conn – psycopg2 connection object
- cur – psycopg2 cursor object
-
add_league(league)¶ inserts a new row to the leagues table with values of the given league attributes.
Parameters: league – new League object
-
delete_league(_id)¶ deletes the row from the leagues table whose id is given _id.
Parameters: _id – id of the row - int
-
get_league(_id)¶ Returns
final4.models.league.Leagueobject with values from the leagues table IF there is a record has a given _id ELSE returns None.Parameters: _id – id of the row - int Returns: league or None Return type: final4.models.league.Leagueobject or None
-
get_leagues(limit=100, offset=0)¶ Returns result list and total number of results. Returning list is list of
final4.models.league.Leagueobject. All objects filled up with values from the rows of the leagues table. Also returns the total number of the result.Parameters: - limit – maximum number of the result
- offset – skip beginning of the result
Returns: leaguelist, total
Return type: list, int
-
get_leagues_by(attrib, search_key, limit=100, offset=0)¶ Returns result list and total number of result. Returning list is list of
final4.models.league.Leagueobject. All objects filled up with values from the rows of the leagues table.The return list made up by filtered results with given parameters.
Parameters: - limit – maximum number of the result
- offset – skip beginning of the result
Returns: leaguelist, total
Return type: list, int
-
get_leagues_search_by(attrib, search_key, limit=100, offset=0)¶ Returns result list and total number of result. Returning list is list of
final4.models.league.Leagueobject. All objects filled up with values from the rows of the leagues table.The return list made up by filtered results with given parameters.
Parameters: - limit – maximum number of the result
- offset – skip beginning of the result
Returns: leaguelist, total
Return type: list, int
-
update_league(_id, new)¶ Updates the row from the leagues table whose id is given _id. The new values is taken from given new League object.
Parameters: - _id – id of the row - int
- new – League object with new values
-
final4.models.league.leaguetable= ['id', 'name', 'country_id', 'country']¶ corresponding key values of the League class attributes
final4.models.user¶
User class and Database connection handlers¶
-
class
final4.models.user.User(username, password, email, role='admin', lastlogin=None, regtime=None, online=False)¶ User object
-
classmethod
fromDict(ud)¶ creates a new User object from given dictionary
-
getAttrs()¶ returns all attributes of the User object as a tuple
-
classmethod
-
class
final4.models.user.Users(conn, cur)¶ the Users object provides functions for database connections of users table.
Parameters: - conn – psycopg2 connection object
- cur – psycopg2 cursor object
-
add_user(user)¶ inserts a new row to the users table with values of the given user attributes.
Parameters: user – new User object
-
delete_user(username)¶ deletes the row from the users table whose username is given as parameter.
Parameters: username – username string
-
get_user(username)¶ returns
final4.models.user.Userobject with values from the users table IF there is a record has a given username ELSE returns None.Parameters: username – username string Returns: user or None Return type: final4.models.user.Userobject or None
-
get_users()¶ returns list of
final4.models.user.Userobject. All objects filled up with values from the rows of the users table.Returns: userlist Return type: list
-
update_user(username, user)¶ updates the row from the users table whose username is given username. The new values is taken from given user.
Parameters: - username – username string
- user – User object with new values
-
final4.models.user.usertable= ['id', 'username', 'password', 'email', 'role', 'lastlogin', 'regtime', 'online']¶ corresponding key values of the User class attributes
Views¶
final4.views.coach_view¶
-
final4.views.coach_view.coach_from_id(lid)¶ Routing function for getting coach from its id.
GET request returns JSON object.
POST request updates coach which has id equal to the lid with the values recieved from the request.form. After all it renders coaches.html
Parameters: lid – id of the coach, int
-
final4.views.coach_view.coach_page()¶ Routing function for coach-table page.
This page has session control. see session controlled pages
This page lists coaches and allows adding, deleting, and updating on them.
-
final4.views.coach_view.coaches_home()¶ Routing function for coaches-home page.
This view page lists all coaches in coaches table. This page doesn’t allow editing.
-
final4.views.coach_view.search_coach(key)¶ Routing function for search coach by its name.
GET request renders the countries.html with coaches comes from the search result.
final4.views.country_view¶
-
final4.views.country_view.countries_home()¶ Routing function for countries-home page.
This view page lists all countries in countries table. This page doesn’t allow editing.
-
final4.views.country_view.country_from_id(cid)¶ Routing function for getting country from its id.
GET request returns JSON object.
POST request updates country which has id equal to the cid with the values recieved from the request.form. After all it renders countries.html
Parameters: cid – id of the country, int
-
final4.views.country_view.country_page()¶ Routing function for country-table page.
This page has session control. see session controlled pages
This page lists countries and allows adding, deleting, and updating on them.
-
final4.views.country_view.search_country(key)¶ Routing function for search country by its name.
GET request renders the countries.html with leagues comes from the search result.
-
final4.views.country_view.view_country(country_name)¶ Routing function for country info page.
This view renders the country_page.html with the general information and related table statistics for given country.
Parameters: country_name – name of the country, string
final4.views.league_view¶
-
final4.views.league_view.league_from_id(lid)¶ Routing function for getting league from its id.
GET request returns JSON object.
POST request updates league which has id equal to the lid with the values recieved from the request.form. After all it renders leagues.html
Parameters: lid – id of the league, int
-
final4.views.league_view.league_page()¶ Routing function for league-table page.
This page has session control. see session controlled pages
This page lists leagues and allows adding, deleting, and updating on them.
-
final4.views.league_view.leagues_home()¶ Routing function for leagues-home page.
This view page lists all leagues in leagues table. This page doesn’t allow editing.
-
final4.views.league_view.search_league(key)¶ Routing function for search league by its name.
GET request renders the leagues.html with leagues comes from the search result.
-
final4.views.league_view.view_league(league_id)¶ Routing function for league info page.
It renders the league_page.html with related statistical information.
final4.views.login_view¶
-
final4.views.login_view.admin()¶ Routing function for admin page. This page allows POST and GET requests.
GET request: If the user signed in adminpanel page is rendered. Otherwise signin page is rendered.
POST request: Checks the request.form values for registered users. If the values are valid it adds user to the session and renders the adminpanel. Otherwise error message is flashed.
-
final4.views.login_view.logout()¶ Routing function for logout page.
When this page called if there is a user logged in, then the user removed from the session.
After all it redirects to the home page.
-
final4.views.login_view.profile(username)¶ Routing function for user profile page. Renders templates/profile.html for user which has given username.
Parameters: username – username string
-
final4.views.login_view.signin()¶ Routing function for signin page.
-
final4.views.login_view.signup()¶ Routing function for signup page.
It allows only POST request. If the valid values are gotten from the request.form then new user is created and inserted to the db.
-
final4.views.login_view.updateUser()¶ Routing function for updating user. This url allows only POST request.
Updates the user which attributes recieved from request.form and returns the JSON object.
Returns: status and error Return type: JSON object
-
final4.views.login_view.users()¶ Routing function for users page.