]> git.xonotic.org Git - xonotic/xonstat.git/commitdiff
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 0ae5a5230b9beb52ec451d8d17167aea7c33f6fc..56f4260278bf2664b21238d3e10b9508c2e1e618 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 a0f08951384be0523eaf9938da00472215f6c1b5..2d39e103b89e613fff6bdbf540d296ebeb9f908c 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 83238adb5c59d194bab3f277052fe85b1fd7b406..ff3a33f990ffe7d85a6e380fd14874c11cd9f478 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,
             }