config.add_route(name="player_info", pattern="/player/{id:\d+}", view=player_info,
renderer='player_info.mako')
+ config.add_route(name="game_index", pattern="/games", view=game_index,
+ renderer='game_index.mako')
+
+ config.add_route(name="game_index_paged", pattern="/games/page/{page:\d+}",
+ view=game_index, renderer='game_index.mako')
+
config.add_route(name="game_info", pattern="/game/{id:\d+}", view=game_info,
renderer='game_info.mako')
--- /dev/null
+<%inherit file="base.mako"/>\r
+\r
+<%block name="title">\r
+Game Index - ${parent.title()}\r
+</%block>\r
+\r
+% if not games:\r
+<h2>Sorry, no games yet. Get playing!</h2>\r
+\r
+% else:\r
+<h2>Recent Games</h2>\r
+<ul>\r
+% for (game_id, server_id, server_name, map_id, map_name) in games:\r
+ <li>game <a href="${request.route_url("game_info", id=game_id)}" name="Game info page for game #${game_id}">#${game_id}:</a> <a href="${request.route_url("map_info", id=map_id)}" name="Map info page for ${map_name}">${map_name}</a> on <a href="${request.route_url("server_info", id=server_id)}" name="Server info page for ${server_name}">${server_name}</a></li>\r
+% endfor\r
+</ul>\r
+% endif\r
import re
from pyramid.response import Response
from pyramid.view import view_config
+from webhelpers.paginate import Page, PageURL
from xonstat.models import *
from sqlalchemy.orm.exc import MultipleResultsFound, NoResultFound
player = DBSession.query(Player).filter_by(player_id=player_id).one()
recent_games = DBSession.query("game_id", "server_id", "server_name",
"map_id", "map_name").\
- from_statement("select g.game_id, s.server_id, s.name as server_name, m.map_id, m.name as map_name "
+ from_statement("select g.game_id, s.server_id, "
+ "s.name as server_name, m.map_id, m.name as map_name "
"from player_game_stats gs, games g, servers s, maps m "
"where gs.player_id=:player_id "
"and gs.game_id = g.game_id "
# This is the game views area - only views pertaining to Xonotic
# games and their related information goes here
##########################################################################
+def page_url(page):
+ return current_route_url(request, page=page, _query=request.GET)
+
+def game_index(request):
+ if 'page_number' in request.matchdict:
+ current_page = request.matchdict['page_number']
+ else:
+ current_page = 1
+
+ games_q = DBSession.query("game_id", "server_id", "server_name",
+ "map_id", "map_name").\
+ from_statement("select g.game_id, s.server_id, "
+ "s.name as server_name, m.map_id, m.name as map_name "
+ "from games g, servers s, maps m "
+ "where g.server_id = s.server_id "
+ "and g.map_id = m.map_id "
+ "order by g.start_dt desc")
+
+ games = Page(games_q, current_page, url=page_url)
+
+ return {'games':games}
+
+
def game_info(request):
game_id = request.matchdict['id']
try: