]> git.rm.cloudns.org Git - xonotic/xonstat.git/commitdiff
Adding gametype-filtered game_index view (and fix bug in player_game_index)
authorJan Behrens <zykure@web.de>
Wed, 17 Apr 2013 07:10:53 +0000 (09:10 +0200)
committerJan Behrens <zykure@web.de>
Wed, 17 Apr 2013 07:10:53 +0000 (09:10 +0200)
Not linked anywhere yet, but can be accessed via .../player/###/games/gametype

xonstat/__init__.py
xonstat/templates/player_game_index.mako
xonstat/views/helpers.py
xonstat/views/player.py

index 08946adb2431b7f7221216ed89dbaeb0f2fc2daf..ee594adbd81f6a3cae16412fda479c3eb99f9c5d 100644 (file)
@@ -41,6 +41,11 @@ def main(global_config, **settings):
     config.add_view(player_game_index,      route_name="player_game_index",      renderer="player_game_index.mako")
     config.add_view(player_game_index_json, route_name="player_game_index_json", renderer="jsonp")
 
+    config.add_route("player_game_index_filtered",      "/player/{player_id:\d+}/games/{game_type_cd:\w+}")
+    config.add_route("player_game_index_filtered_json", "/player/{player_id:\d+}/games/{game_type_cd:\w+}.json")
+    config.add_view(player_game_index,      route_name="player_game_index_filtered",      renderer="player_game_index.mako")
+    config.add_view(player_game_index_json, route_name="player_game_index_filtered_json", renderer="jsonp")
+
     config.add_route("player_info",      "/player/{id:\d+}")
     config.add_route("player_info_json", "/player/{id:\d+}.json")
     config.add_view(player_info,      route_name="player_info",      renderer="player_info.mako")
index 1953cb28dfecc2c64a42bac438cfcf30c8f4cec9..77535fe1746e0fa4286f31a3d2c156a489263925 100644 (file)
@@ -17,7 +17,11 @@ Recent Games
 % else:
 <div class="row">
   <div class="span12">
+    % if not game_type_cd:
     <h3>Recent Games by ${player.nick_html_colors()|n}</h3>
+    % else:
+    <h3>Recent ${game_type_cd.upper()} Games by ${player.nick_html_colors()|n}</h3>
+    % endif
     <p><a href="${player_url}">Back to player info page</a></p>
   </div>
 </div>
index cbaed249074a6ecd951d6761841ed86193e7ffb7..2f2db70ee3e451312d0616fca930365f6a9122d8 100644 (file)
@@ -75,7 +75,7 @@ class RecentGame(object):
         return "<RecentGame(id=%s, gametype=%s, server=%s, map=%s)>" % (self.game_id, self.game_type_cd, self.server_name, self.map_name)
 
 
-def recent_games_q(server_id=None, map_id=None, player_id=None, cutoff=None):
+def recent_games_q(server_id=None, map_id=None, player_id=None, game_type_cd=None, cutoff=None):
     '''
     Returns a SQLA query of recent game data. Parameters filter
     the results returned if they are provided. If not, it is
@@ -113,6 +113,10 @@ def recent_games_q(server_id=None, map_id=None, player_id=None, cutoff=None):
         recent_games_q = recent_games_q.\
             filter(PlayerGameStat.rank==1)
 
+    if game_type_cd is not None:
+        recent_games_q = recent_games_q.\
+            filter(Game.game_type_cd==game_type_cd.lower())
+
     if cutoff is not None:
         right_now = datetime.utcnow()
         recent_games_q = recent_games_q.\
index a183114bd341dbafd0767ad6b0ce290dbad1e4ad..c0379017be4f2738c8fc665e7ac04ea9bf9bab14 100644 (file)
@@ -596,6 +596,10 @@ def player_info_json(request):
 
 def player_game_index_data(request):
     player_id = request.matchdict['player_id']
+    try:
+        game_type_cd  = request.matchdict['game_type_cd']
+    except:
+        game_type_cd  = None
 
     if request.params.has_key('page'):
         current_page = request.params['page']
@@ -603,10 +607,12 @@ def player_game_index_data(request):
         current_page = 1
 
     try:
-        player = DBSession.query(Player).filter_by(player_id=player_id).\
-                filter(Player.active_ind == True).one()
+        player = DBSession.query(Player).\
+                filter_by(player_id=player_id).\
+                filter(Player.active_ind == True).\
+                one()
 
-        rgs_q = recent_games_q(player_id=player.player_id)
+        rgs_q = recent_games_q(player_id=player.player_id, game_type_cd=game_type_cd)
 
         games = Page(rgs_q, current_page, items_per_page=10, url=page_url)
 
@@ -619,8 +625,10 @@ def player_game_index_data(request):
 
     return {
             'player_id':player.player_id,
+            'player_url':request.route_url('player_info', id=player_id),
             'player':player,
             'games':games,
+            'game_type_cd':game_type_cd,
            }
 
 
@@ -641,7 +649,6 @@ def player_game_index_json(request):
     """
     return [{'status':'not implemented'}]
 
-
 def player_accuracy_data(request):
     player_id = request.matchdict['id']
     allowed_weapons = ['nex', 'rifle', 'shotgun', 'uzi', 'minstanex']