Show player medals on the player_info page.
authorAnt Zucaro <azucaro@gmail.com>
Tue, 29 Mar 2016 01:11:43 +0000 (21:11 -0400)
committerAnt Zucaro <azucaro@gmail.com>
Tue, 29 Mar 2016 01:11:43 +0000 (21:11 -0400)
xonstat/models.py
xonstat/templates/player_info.mako
xonstat/views/player.py

index 0ae5a52..56f4260 100644 (file)
@@ -428,6 +428,12 @@ class ActiveMap(object):
         return "<ActiveMap(%s, %s)>" % (self.sort_order, self.map_id)
 
 
+class PlayerMedal(object):
+    def __repr__(self):
+        return "<PlayerRank(pid=%s, place=%s, alt=%s)>" % (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)
index a0f0895..2d39e10 100644 (file)
 
 <div class="row">
   <div class="small-12 columns">
-    <h2> ${player.nick_html_colors()|n} </h2>
+    <h2> 
+      ${player.nick_html_colors()|n} 
+      % for medal in medals:
+        <img src="/static/medals/${medal.image}" alt="${medal.alt}" title="${medal.alt}" />
+      % endfor
+    </h2>
+
     <h5>
       <i><span class="abstime" data-epoch="${player.epoch()}" title="${player.create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">Joined ${player.joined_pretty_date()}</span> (player #${player.player_id})</i>
       % if cake_day:
         <img src="/static/images/icons/24x24/cake.png" title="Happy cake day!" />
       % endif
     </h5>
-    <br />
   </div>
 </div>
 
index 83238ad..ff3a33f 100644 (file)
@@ -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,
             }