]> de.git.xonotic.org Git - xonotic/xonstat.git/commitdiff
Game searches.
authorAnt Zucaro <azucaro@gmail.com>
Tue, 13 Dec 2011 20:45:49 +0000 (15:45 -0500)
committerAnt Zucaro <azucaro@gmail.com>
Tue, 13 Dec 2011 20:45:49 +0000 (15:45 -0500)
xonstat/templates/search.mako
xonstat/views/search.py

index c364c7423e923e710f632e26e1c5b72fcee59201..64e5cedb3918bc892cf686d919e8de6f40156220 100644 (file)
     % endfor
 </table>
 % endif
+
+##### game results #####
+% if result_type == "game":
+<table>
+    <tr>
+        <th>Game ID</th>
+        <th>Map</th>
+        <th>Server</th>
+        <th>Played On</th>
+    </tr>
+    % for (game, server, gmap) in results:
+    <tr>
+        <td><a href="${request.route_url("game_info", id=game.game_id)}" name="Game info page for game #${game.game_id}">${game.game_id}</a></td>
+        <td><a href="${request.route_url("map_info", id=gmap.map_id)}" name="Map info page for map #${gmap.map_id}">${gmap.name}</a></td>
+        <td><a href="${request.route_url("server_info", id=server.server_id)}" name="Server info page for server #${server.server_id}">${server.name}</a></td>
+        <td>${game.create_dt.strftime('%m/%d/%Y at %I:%M %p')}</td>
+    </tr>
+    % endfor
+</table>
+% endif
index b8b3ab5453920ce5b7a5ed5728a0804f289e66d9..11c22eb6617c537ddcc48a211ba8c92543c4dbbe 100644 (file)
@@ -4,6 +4,7 @@ import pyramid.httpexceptions
 import re
 import time
 from pyramid.response import Response
+from sqlalchemy import desc
 from sqlalchemy.orm.exc import MultipleResultsFound, NoResultFound
 from sqlalchemy.sql import func
 from xonstat.models import *
@@ -13,41 +14,52 @@ from webhelpers.paginate import Page, PageURL
 
 log = logging.getLogger(__name__)
 
-def search_q(player_id=None, nick=None, server_id=None, server_name=None,
-        map_id=None, map_name=None, game_id=None, create_dt=None):
+def search_q(nick=None, server_name=None, map_name=None, create_dt=None):
     session     = DBSession()
     result_type = None
     q           = None
 
     # player-only searches
-    if ((player_id or nick) and not server_id and not server_name and not
-            map_id and not map_name and not game_id and not create_dt):
+    if nick and not server_name and not map_name and not create_dt:
         result_type = "player"
         q = session.query(Player)
         if nick:
-            q = q.filter(func.upper(Player.stripped_nick).like('%'+nick.upper()+'%'))
-        if player_id:
-            q = q.filter(Player.player_id==player_id)
+            q = q.filter(
+                    func.upper(Player.stripped_nick).like('%'+nick.upper()+'%'))
+
     # server-only searches
-    elif ((server_id or server_name) and not player_id and not nick and not
-            map_id and not map_name and not game_id and not create_dt):
+    elif server_name and not nick and not map_name and not create_dt:
         result_type = "server"
         q = session.query(Server)
         if server_name:
             q = q.filter(func.upper(Server.name).\
                     like('%'+server_name.upper()+'%'))
-        if server_id:
-            q = q.filter(Server.server_id==server_id)
+
     # map-only searches
-    elif ((map_id or map_name) and not player_id and not nick and not
-            server_id and not server_name and not game_id and not create_dt):
+    elif map_name and not nick and not server_name and not create_dt:
         result_type = "map"
         q = session.query(Map)
         if map_name:
             q = q.filter(func.upper(Map.name).\
                     like('%'+map_name.upper()+'%'))
-        if map_id:
-            q = q.filter(Map.map_id==map_id)
+
+    # game searches (all else)
+    else:
+        result_type = "game"
+        q = session.query(Game, Server, Map).\
+                filter(Game.server_id == Server.server_id).\
+                filter(Game.map_id == Map.map_id).\
+                order_by(Game.game_id.desc())
+        if nick:
+            q = q.filter(func.upper(PlayerGameStat.stripped_nick).\
+                    like('%'+nick.upper()+'%')).\
+                filter(PlayerGameStat.game_id == Game.game_id)
+        if map_name:
+            q = q.filter(func.upper(Map.name).\
+                    like('%'+map_name.upper()+'%'))
+        if server_name:
+            q = q.filter(func.upper(Server.name).\
+                    like('%'+server_name.upper()+'%'))
 
     return (result_type, q)