Add server index and template. Fix links on player index and template.
[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=main_index,
26             renderer='main_index.mako') 
27
28     # PLAYER ROUTES
29     config.add_route(name="player_game_index_default", 
30             pattern="/player/{player_id:\d+}/games", 
31             view=player_game_index, renderer='player_game_index.mako') 
32
33     config.add_route(name="player_game_index", 
34             pattern="/player/{player_id:\d+}/games/page/{page:\d+}", 
35             view=player_game_index, renderer='player_game_index.mako') 
36
37     config.add_route(name="player_index_paged", 
38             pattern="/players/page/{page:\d+}", view=player_index, 
39             renderer='player_index.mako') 
40
41     config.add_route(name="player_index", pattern="/players", view=player_index, 
42             renderer='player_index.mako') 
43
44     config.add_route(name="player_info", pattern="/player/{id:\d+}", view=player_info, 
45             renderer='player_info.mako') 
46
47     # GAME ROUTES
48     config.add_route(name="game_index", pattern="/games", view=game_index, 
49             renderer='game_index.mako') 
50
51     config.add_route(name="game_index_paged", pattern="/games/page/{page:\d+}", 
52             view=game_index, renderer='game_index.mako') 
53
54     config.add_route(name="game_info", pattern="/game/{id:\d+}", view=game_info, 
55             renderer='game_info.mako') 
56
57     # SERVER ROUTES
58     config.add_route(name="server_index_paged", 
59             pattern="/servers/page/{page:\d+}", view=server_index, 
60             renderer='server_index.mako') 
61
62     config.add_route(name="server_index", pattern="/servers", view=server_index, 
63             renderer='server_index.mako') 
64
65     config.add_route(name="server_game_index", 
66             pattern="/server/{server_id:\d+}/games/page/{page:\d+}", 
67             view=server_game_index, renderer='server_game_index.mako') 
68
69     config.add_route(name="server_info", pattern="/server/{id:\d+}", view=server_info, 
70             renderer='server_info.mako') 
71
72     # MAP ROUTES
73     config.add_route(name="map_index_paged", 
74             pattern="/maps/page/{page:\d+}", view=map_index, 
75             renderer='map_index.mako') 
76
77     config.add_route(name="map_index", pattern="/maps", view=map_index, 
78             renderer='map_index.mako') 
79
80     config.add_route(name="map_info", pattern="/map/{id:\d+}", view=map_info, 
81             renderer='map_info.mako') 
82
83     config.add_route(name="stats_submit", pattern="stats/submit", 
84             view=stats_submit, renderer='index.jinja2') 
85
86     return config.make_wsgi_app()