+<%inherit file="base.mako"/>
+
% if results == None:
<form action="${request.route_url("search")}" method="get">
- <input type="hidden" name="form.submitted" />
- Nick: <input type="text" name="nick" /> <br />
- <input type="submit" />
-</form>
+ <input type="hidden" name="form_submitted" />
+ <table id="search_form" border="0">
+ <tr>
+ <td style="text-align:right;">Nick:</td>
+ <td><input type="text" name="nick" /></td>
+ </tr>
+ <tr>
+ <td style="text-align:right;">Server:</td>
+ <td><input type="text" name="server_name" /></td>
+ </tr>
+ <tr>
+ <td style="text-align:right;">Map:</td>
+ <td><input type="text" name="map_name" /></td>
+ </tr>
+ <tr>
+ <td style="text-align:right;"></td>
+ <td><input type="submit" /></td>
+ </tr>
+ </table>
+ </form>
% endif
+##### player-only results #####
% if result_type == "player":
<table>
<tr>
</tr>
% for player in results:
<tr>
- <td>${player.nick_html_colors()|n}</td>
+ <td><a href="${request.route_url("player_info", id=player.player_id)}" name="Player info page for player #${player.player_id}">${player.nick_html_colors()|n}</a></td>
<td>${player.joined_pretty_date()}</td>
</tr>
% endfor
</table>
% endif
+
+##### server-only results #####
+% if result_type == "server":
+<table>
+ <tr>
+ <th>Server</th>
+ <th>Created</th>
+ </tr>
+ % for server in results:
+ <tr>
+ <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>${server.create_dt.strftime('%m/%d/%Y at %I:%M %p')}</td>
+ </tr>
+ % endfor
+</table>
+% endif
+
+##### map-only results #####
+% if result_type == "map":
+<table>
+ <tr>
+ <th>Map</th>
+ <th>Created</th>
+ </tr>
+ % for map in results:
+ <tr>
+ <td><a href="${request.route_url("map_info", id=map.map_id)}" name="Map info page for map #${map.map_id}">${map.name}</a></td>
+ <td>${map.create_dt.strftime('%m/%d/%Y at %I:%M %p')}</td>
+ </tr>
+ % endfor
+</table>
+% endif
from sqlalchemy.sql import func
from xonstat.models import *
from xonstat.util import strip_colors, qfont_decode
+from xonstat.util import page_url, html_colors
+from webhelpers.paginate import Page, PageURL
log = logging.getLogger(__name__)
map_id=None, map_name=None, game_id=None, create_dt=None):
session = DBSession()
result_type = None
- results = None
+ q = None
# player-only searches
if ((player_id or nick) and not server_id and not server_name and not
q = q.filter(func.upper(Player.stripped_nick).like('%'+nick.upper()+'%'))
if player_id:
q = q.filter(Player.player_id==player_id)
+ # 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):
+ 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):
+ 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)
- try:
- results = q.all()
- except:
- result_type = None
- results = None
-
- return (result_type, results)
+ return (result_type, q)
def search(request):
+ form_submitted = None
+ nick = None
+ server_name = None
+ map_name = None
result_type = None
results = None
- if request.params.has_key('form.submitted'):
+ if request.params.has_key('form_submitted'):
nick = request.params['nick']
- (result_type, results) = search_q(nick=nick)
+ server_name = request.params['server_name']
+ map_name = request.params['map_name']
+ (result_type, q) = search_q(nick=nick, server_name=server_name,
+ map_name=map_name)
+ log.debug(q)
+
+ try:
+ if q != None:
+ results = q.all()
+ except Exception as e:
+ raise e
+ result_type = None
+ results = None
return {'result_type':result_type,
'results':results,