From 20f7329a36f304c8ba9dc439b64cea96865a538d Mon Sep 17 00:00:00 2001 From: Ant Zucaro Date: Mon, 28 Mar 2016 21:11:43 -0400 Subject: [PATCH] Show player medals on the player_info page. --- xonstat/models.py | 8 ++++++++ xonstat/templates/player_info.mako | 9 +++++++-- xonstat/views/player.py | 19 +++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/xonstat/models.py b/xonstat/models.py index 0ae5a52..56f4260 100644 --- a/xonstat/models.py +++ b/xonstat/models.py @@ -428,6 +428,12 @@ class ActiveMap(object): return "" % (self.sort_order, self.map_id) +class PlayerMedal(object): + def __repr__(self): + return "" % (self.player_id, + self.place, self.alt) + + def initialize_db(engine=None): DBSession.configure(bind=engine) Base.metadata.bind = engine @@ -459,6 +465,7 @@ def initialize_db(engine=None): active_players_table = MetaData.tables['active_players_mv'] active_servers_table = MetaData.tables['active_servers_mv'] active_maps_table = MetaData.tables['active_maps_mv'] + player_medals_table = MetaData.tables['player_medals'] # now map the tables and the objects together mapper(PlayerAchievement, achievements_table) @@ -483,3 +490,4 @@ def initialize_db(engine=None): mapper(ActivePlayer, active_players_table) mapper(ActiveServer, active_servers_table) mapper(ActiveMap, active_maps_table) + mapper(PlayerMedal, player_medals_table) diff --git a/xonstat/templates/player_info.mako b/xonstat/templates/player_info.mako index a0f0895..2d39e10 100644 --- a/xonstat/templates/player_info.mako +++ b/xonstat/templates/player_info.mako @@ -58,14 +58,19 @@
-

${player.nick_html_colors()|n}

+

+ ${player.nick_html_colors()|n} + % for medal in medals: + ${medal.alt} + % endfor +

+
Joined ${player.joined_pretty_date()} (player #${player.player_id}) % if cake_day: % endif
-
diff --git a/xonstat/views/player.py b/xonstat/views/player.py index 83238ad..ff3a33f 100644 --- a/xonstat/views/player.py +++ b/xonstat/views/player.py @@ -494,6 +494,23 @@ def get_damage_stats(player_id, weapon_cd, games): return (avg, dmgs) +def get_player_medals(player_id): + """Retrieves the list of medals the player has received from tournaments or + other contests.""" + try: + medals = DBSession.query(PlayerMedal)\ + .filter(PlayerMedal.player_id==player_id)\ + .order_by(PlayerMedal.place)\ + .order_by(PlayerMedal.create_dt)\ + .all() + + return medals + + except Exception as e: + log.debug(e) + return [] + + def player_info_data(request): player_id = int(request.matchdict['id']) if player_id <= 2: @@ -508,6 +525,7 @@ def player_info_data(request): fav_maps = get_fav_maps(player_id) elos = get_elos(player_id) ranks = get_ranks(player_id) + medals = get_player_medals(player_id) recent_games = get_recent_games(player_id) cake_day = is_cake_day(player.create_dt) @@ -523,6 +541,7 @@ def player_info_data(request): 'fav_maps':fav_maps, 'elos':elos, 'ranks':ranks, + 'medals':medals, 'recent_games':recent_games, 'cake_day':cake_day, } -- 2.39.2