]> git.rm.cloudns.org Git - xonotic/xonstat.git/commitdiff
Add a basic game finder view at the /gamefinder URL.
authorAnt Zucaro <azucaro@gmail.com>
Mon, 24 Dec 2012 14:38:34 +0000 (09:38 -0500)
committerAnt Zucaro <azucaro@gmail.com>
Mon, 24 Dec 2012 14:38:34 +0000 (09:38 -0500)
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.

xonstat/__init__.py
xonstat/views/__init__.py
xonstat/views/game.py

index e334af5876e4fd55dba2179369a1954faedbe930..a18a6a12e038b9393f67cf5e0b500adbe0335d70 100644 (file)
@@ -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")
index 44578491827a197893827a145623cc25c5156afb..ac029dbd44584bb5cee566a4e490d970228ab578 100644 (file)
@@ -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
index f9389e0bc10821a4c73aae68324c96ee44b625c1..44d9bb131481654253af87f1e2875e515d986669 100644 (file)
@@ -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)