]> git.xonotic.org Git - xonotic/xonstat.git/blob - xonstat/__init__.py
Add a default player game index route (goes to page 1 of results).
[xonotic/xonstat.git] / xonstat / __init__.py
1 import pyramid_jinja2
2 import sqlahelper
3 from pyramid.config import Configurator
4 from sqlalchemy import engine_from_config
5 from xonstat.models import initialize_db
6 from xonstat.views import * 
7
8 def main(global_config, **settings):
9     """ This function returns a Pyramid WSGI application.
10     """
11     # setup the database engine
12     engine = engine_from_config(settings, 'sqlalchemy.')
13     sqlahelper.add_engine(engine)
14
15     # initialize database structures
16     initialize_db(engine)
17
18     config = Configurator(settings=settings)
19
20     config.add_renderer('.jinja2', pyramid_jinja2.renderer_factory)
21
22     config.add_static_view('static', 'xonstat:static')
23
24     # ROOT ROUTE
25     config.add_route(name="main_index", pattern="/", view=game_index,
26             renderer='game_index.mako') 
27
28     # PLAYER ROUTES
29     config.add_route(name="player_weapon_stats", 
30             pattern="/game/{game_id:\d+}/stats/{pgstat_id:\d+}", 
31             view=player_weapon_stats, renderer='player_weapon_stats.mako') 
32
33     config.add_route(name="player_game_index_default", 
34             pattern="/player/{player_id:\d+}/games", 
35             view=player_game_index, renderer='player_game_index.mako') 
36
37     config.add_route(name="player_game_index", 
38             pattern="/player/{player_id:\d+}/games/page/{page:\d+}", 
39             view=player_game_index, renderer='player_game_index.mako') 
40
41     config.add_route(name="player_info", pattern="/player/{id:\d+}", view=player_info, 
42             renderer='player_info.mako') 
43
44     # GAME ROUTES
45     config.add_route(name="game_index", pattern="/games", view=game_index, 
46             renderer='game_index.mako') 
47
48     config.add_route(name="game_index_paged", pattern="/games/page/{page:\d+}", 
49             view=game_index, renderer='game_index.mako') 
50
51     config.add_route(name="game_info", pattern="/game/{id:\d+}", view=game_info, 
52             renderer='game_info.mako') 
53
54     # SERVER ROUTES
55     config.add_route(name="server_game_index", 
56             pattern="/server/{server_id:\d+}/games/page/{page:\d+}", 
57             view=server_game_index, renderer='server_game_index.mako') 
58
59     config.add_route(name="server_info", pattern="/server/{id:\d+}", view=server_info, 
60             renderer='server_info.mako') 
61
62     # MAP ROUTES
63     config.add_route(name="map_info", pattern="/map/{id:\d+}", view=map_info, 
64             renderer='map_info.mako') 
65
66     config.add_route(name="stats_submit", pattern="stats/submit", 
67             view=stats_submit, renderer='index.jinja2') 
68
69     return config.make_wsgi_app()