Merge branch 'master' into zykure/approved
authorJan Behrens <zykure@web.de>
Sat, 20 Apr 2013 09:47:05 +0000 (11:47 +0200)
committerJan Behrens <zykure@web.de>
Sat, 20 Apr 2013 09:47:05 +0000 (11:47 +0200)
Conflicts:
xonstat/templates/player_game_index.mako

xonstat/__init__.py
xonstat/templates/game_finder.mako
xonstat/templates/main_index.mako
xonstat/templates/player_game_index.mako
xonstat/views/game.py
xonstat/views/helpers.py
xonstat/views/player.py

index 08946adb2431b7f7221216ed89dbaeb0f2fc2daf..bbd08bf7485559650228867bb59fd67d0ede5262 100644 (file)
@@ -74,10 +74,10 @@ def main(global_config, **settings):
     config.add_view(player_captimes_json, route_name="player_captimes_json", renderer="jsonp")
 
     # GAME ROUTES
-    config.add_route("game_index",      "/games")
-    config.add_route("game_index_json", "/games.json")
-    config.add_view(game_index,      route_name="game_index",      renderer="game_index.mako")
-    config.add_view(game_index_json, route_name="game_index_json", renderer="jsonp")
+    config.add_route("game_index",      "/games")
+    config.add_route("game_index_json", "/games.json")
+    config.add_view(game_index,      route_name="game_index",      renderer="game_index.mako")
+    config.add_view(game_index_json, route_name="game_index_json", renderer="jsonp")
 
     config.add_route("game_info",      "/game/{id:\d+}")
     config.add_route("game_info_json", "/game/{id:\d+}.json")
@@ -89,8 +89,8 @@ def main(global_config, **settings):
     config.add_view(rank_index,      route_name="rank_index",      renderer="rank_index.mako")
     config.add_view(rank_index_json, route_name="rank_index_json", renderer="jsonp")
 
-    config.add_route("game_finder", "/gamefinder")
-    config.add_view(game_finder, route_name="game_finder", renderer="game_finder.mako")
+    config.add_route("game_index", "/games")
+    config.add_view(game_finder, route_name="game_index", renderer="game_finder.mako")
 
     # SERVER ROUTES
     config.add_route("server_index",      "/servers")
index cff48762af2548b38cf3f11200d5dd2bccdb21d4..fc96277480a0ec6557607e015ba05d1015e8b729 100644 (file)
@@ -11,10 +11,41 @@ ${nav.nav('games')}
     <link href="/static/css/sprites.css" rel="stylesheet">
 </%block>
 
+<%block name="title">
+Game Index
+</%block>
+
 % if len(recent_games) > 0:
+
+##### ROW OF GAME TYPE ICONS #####
+<div class="row">
+  <div class="span12 tabbable">
+    <ul class="nav nav-tabs">
+      % for gt in ('overall','duel','ctf','dm','tdm','ca','kh','ft','lms','as','dom','nb','cts','rc'):
+      <li 
+      % if game_type_cd == gt or (game_type_cd is None and gt == 'overall'):
+      class="active"
+      % endif
+      >
+
+      % if gt == 'overall':
+      <a href="${request.route_url("game_index")}" alt="${gt}" title="" data-toggle="none">
+      % else:
+      <a href="${request.route_url("game_index", _query={'type':gt})}" alt="${gt}" title="" data-toggle="none">
+      % endif
+        <span class="sprite sprite-${gt}"> </span><br />
+        ${gt} <br />
+      </a>
+      </li>
+      % endfor
+    </ul>
+    <br />
+  </div>
+</div>
+
+##### RECENT GAMES TABLE #####
 <div class="row">
   <div class="span12">
-    <h3>Recent Games</h3>
     <table class="table table-hover table-condensed">
       <thead>
         <tr>
@@ -48,5 +79,5 @@ ${nav.nav('games')}
 </div> <!-- /row -->
 
 <!-- navigation links -->
-${navlinks("game_finder", recent_games.page, recent_games.last_page, search_query=query)}
+${navlinks("game_index", recent_games.page, recent_games.last_page, search_query=query)}
 % endif
index a35104e9366b9eef020848951517e6f1aa6716f3..983f2eebb7888ba7a82f10c06886e1ccb3bfc4f1 100644 (file)
@@ -201,7 +201,7 @@ Leaderboard
         % endfor
         </tbody>
     </table>
-    <p><a href="${request.route_url('game_finder')}">More...</a></p>
+    <p><a href="${request.route_url('game_index')}">More...</a></p>
   </div> <!-- /span12 -->
 </div> <!-- /row -->
 % endif
index dabef434500c393a13b06f059d5c06169f975c73..18eeeabb98a8151edd65f5e307866f722fe35a14 100644 (file)
@@ -45,11 +45,15 @@ Recent Games
     <ul class="nav nav-tabs">
       % for game in games_played:
       % if not game.game_type_cd in ['cq']:
-      <li>
+      <li 
+      % if game.game_type_cd == game_type_cd or (game.game_type_cd == 'overall' and game_type_cd is None):
+      class="active"
+      % endif
+      >
       % if game.game_type_cd == 'overall':
       <a href="${request.route_url("player_game_index", player_id=player.player_id)}" alt="${game.game_type_cd}" title="" data-toggle="none">
       % else:
-      <a href="${request.route_url("player_game_index", player_id=player.player_id, _query={'game_type_cd':game.game_type_cd})}" alt="${game.game_type_cd}" title="" data-toggle="none">
+      <a href="${request.route_url("player_game_index", player_id=player.player_id, _query={'type':game.game_type_cd})}" alt="${game.game_type_cd}" title="" data-toggle="none">
       % endif
         <span class="sprite sprite-${game.game_type_cd}"> </span><br />
         ${game.game_type_cd} <br />
index d18da8f7c3dcea28747ed1f194124b345eae753d..f1ba46132d09f330529edf9aafa8f3f994605c2e 100644 (file)
@@ -12,6 +12,7 @@ from xonstat.views.helpers import RecentGame, recent_games_q
 log = logging.getLogger(__name__)
 
 
+# DEPRECATED
 def _game_index_data(request):
     game_type_cd = None
     game_type_descr = None
@@ -216,7 +217,9 @@ def game_finder_data(request):
     query = {}
 
     server_id, map_id, player_id = None, None, None
-    range_start, range_end = None, None
+    range_start, range_end, game_type_cd = None, None, None
+    game_type_descr = None
+
     # these become WHERE clauses when present
     if request.params.has_key('server_id'):
         server_id = request.params['server_id']
@@ -238,8 +241,18 @@ def game_finder_data(request):
         range_end = request.params['range_end']
         query['range_end'] = range_end
 
+    if request.params.has_key('type'):
+        game_type_cd = request.params['type']
+        query['type'] = game_type_cd
+        try:
+            game_type_descr = DBSession.query(GameType.descr).\
+                filter(GameType.game_type_cd == game_type_cd).\
+                one()[0]
+        except Exception as e:
+            game_type_cd = None
+
     rgs_q = recent_games_q(server_id=server_id, map_id=map_id,
-            player_id=player_id)
+            player_id=player_id, game_type_cd=game_type_cd)
 
     recent_games = Page(rgs_q, current_page, url=page_url)
 
@@ -248,6 +261,7 @@ def game_finder_data(request):
     return {
             'recent_games':recent_games,
             'query':query,
+            'game_type_cd':game_type_cd,
            }
 
 def game_finder(request):
index 2f2db70ee3e451312d0616fca930365f6a9122d8..a3b3f535136fe4cfd3754314b5d9068b6ec3d98c 100644 (file)
@@ -1,6 +1,7 @@
 import logging
 import sqlalchemy.sql.expression as expr
 from datetime import datetime
+from sqlalchemy.orm import aliased
 from xonstat.models import *
 from xonstat.util import *
 
@@ -75,7 +76,8 @@ 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, game_type_cd=None, cutoff=None):
+def recent_games_q(server_id=None, map_id=None, player_id=None,
+        game_type_cd=None, cutoff=None, force_player_id=False):
     '''
     Returns a SQLA query of recent game data. Parameters filter
     the results returned if they are provided. If not, it is
@@ -85,6 +87,8 @@ def recent_games_q(server_id=None, map_id=None, player_id=None, game_type_cd=Non
     look when querying. Only games that happened on or after the
     cutoff (which is a datetime object) will be returned.
     '''
+    pgstat_alias = aliased(PlayerGameStat, name='pgstat_alias')
+
     recent_games_q = DBSession.query(Game.game_id, GameType.game_type_cd,
             Game.winner, Game.start_dt, GameType.descr.label('game_type_descr'),
             Server.server_id, Server.name.label('server_name'), Map.map_id,
@@ -106,9 +110,18 @@ def recent_games_q(server_id=None, map_id=None, player_id=None, game_type_cd=Non
         recent_games_q = recent_games_q.\
             filter(Map.map_id==map_id)
 
+    # Note: force_player_id makes the pgstat row returned be from the
+    # specified player_id. Otherwise it will just look for a game
+    # *having* that player_id, but returning the #1 player's pgstat row
     if player_id is not None:
-        recent_games_q = recent_games_q.\
-            filter(PlayerGameStat.player_id==player_id)
+        if force_player_id:
+            recent_games_q = recent_games_q.\
+                filter(PlayerGameStat.player_id==player_id)
+        else:
+            recent_games_q = recent_games_q.\
+                filter(PlayerGameStat.rank==1).\
+                filter(Game.game_id==pgstat_alias.game_id).\
+                filter(pgstat_alias.player_id==player_id)
     else:
         recent_games_q = recent_games_q.\
             filter(PlayerGameStat.rank==1)
index 94fe8cb613d0bec6bce2cc3069f80933fbab90e3..197a4d28b8301cd3e6a05fca75a02d01c2d74421 100644 (file)
@@ -600,8 +600,8 @@ def player_game_index_data(request):
     game_type_cd = None
     game_type_descr = None
 
-    if request.params.has_key('game_type_cd'):
-        game_type_cd = request.params['game_type_cd']
+    if request.params.has_key('type'):
+        game_type_cd = request.params['type']
         try:
             game_type_descr = DBSession.query(GameType.descr).\
                 filter(GameType.game_type_cd == game_type_cd).\
@@ -624,7 +624,8 @@ def player_game_index_data(request):
                 filter(Player.active_ind == True).\
                 one()
 
-        rgs_q = recent_games_q(player_id=player.player_id, game_type_cd=game_type_cd)
+        rgs_q = recent_games_q(player_id=player.player_id,
+            force_player_id=True, game_type_cd=game_type_cd)
 
         games = Page(rgs_q, current_page, items_per_page=10, url=page_url)