% 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
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 *
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)