From: Ant Zucaro Date: Mon, 24 Dec 2012 14:38:34 +0000 (-0500) Subject: Add a basic game finder view at the /gamefinder URL. X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=5694ef974d119126ca9d8d042239121a2548854d;p=xonotic%2Fxonstat.git Add a basic game finder view at the /gamefinder URL. The game finder view is intended to be a better advanced search. We'll see how it works out, but for now at least I can use this view to show more of the "recent games" tables for each entity. --- diff --git a/xonstat/__init__.py b/xonstat/__init__.py index e334af5..a18a6a1 100644 --- a/xonstat/__init__.py +++ b/xonstat/__init__.py @@ -80,6 +80,9 @@ 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") + # SERVER ROUTES config.add_route("server_index", "/servers") config.add_route("server_index_json", "/servers.json") diff --git a/xonstat/views/__init__.py b/xonstat/views/__init__.py index 4457849..ac029db 100644 --- a/xonstat/views/__init__.py +++ b/xonstat/views/__init__.py @@ -8,6 +8,7 @@ from xonstat.views.player import player_elo_info_json from xonstat.views.game import game_index, game_info, rank_index from xonstat.views.game import game_index_json, game_info_json, rank_index_json +from xonstat.views.game import game_finder from xonstat.views.map import map_info, map_index from xonstat.views.map import map_info_json, map_index_json diff --git a/xonstat/views/game.py b/xonstat/views/game.py index f9389e0..44d9bb1 100644 --- a/xonstat/views/game.py +++ b/xonstat/views/game.py @@ -7,6 +7,7 @@ from sqlalchemy import desc, func, over from webhelpers.paginate import Page, PageURL from xonstat.models import * from xonstat.util import page_url +from xonstat.views.helpers import RecentGame, recent_games_q log = logging.getLogger(__name__) @@ -172,3 +173,53 @@ def rank_index_json(request): Provide a list of gametype ranks, paginated. JSON. """ return [{'status':'not implemented'}] + + +def game_finder_data(request): + if request.params.has_key('page'): + current_page = request.params['page'] + else: + current_page = 1 + + query = {} + + server_id, map_id, player_id = None, None, None + range_start, range_end = None, None + # these become WHERE clauses when present + if request.params.has_key('server_id'): + server_id = request.params['server_id'] + query['server_id'] = server_id + + if request.params.has_key('map_id'): + map_id = request.params['map_id'] + query['map_id'] = map_id + + if request.params.has_key('player_id'): + player_id = request.params['player_id'] + query['player_id'] = player_id + + if request.params.has_key('range_start'): + range_start = request.params['range_start'] + query['range_start'] = range_start + + if request.params.has_key('range_end'): + range_end = request.params['range_end'] + query['range_end'] = range_end + + rgs_q = recent_games_q(server_id=server_id, map_id=map_id, + player_id=player_id) + + recent_games = Page(rgs_q, current_page, url=page_url) + + recent_games.items = [RecentGame(row) for row in recent_games.items] + + return { + 'recent_games':recent_games, + 'query':query, + } + +def game_finder(request): + """ + Provide a list of recent games with an advanced filter. + """ + return game_finder_data(request)