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 *
8 def main(global_config, **settings):
9 """ This function returns a Pyramid WSGI application.
11 # setup the database engine
12 engine = engine_from_config(settings, 'sqlalchemy.')
13 sqlahelper.add_engine(engine)
15 # initialize database structures
18 config = Configurator(settings=settings)
20 config.add_renderer('.jinja2', pyramid_jinja2.renderer_factory)
22 config.add_static_view('static', 'xonstat:static')
25 config.add_route("main_index", "/")
26 config.add_view(main_index, route_name="main_index",
27 renderer="main_index.mako")
30 config.add_route("player_game_index_default",
31 "/player/{player_id:\d+}/games")
32 config.add_view(player_game_index, route_name="player_game_index_default",
33 renderer="player_game_index.mako")
35 config.add_route("player_game_index",
36 "/player/{player_id:\d+}/games/page/{page:\d+}")
37 config.add_view(player_game_index, renderer="player_game_index.mako")
39 config.add_route("player_index_paged", "/players/page/{page:\d+}")
40 config.add_view(player_index, route_name="player_index_paged",
41 renderer="player_index.mako")
43 config.add_route("player_index", "/players")
44 config.add_view(player_index, route_name="player_index",
45 renderer="player_index.mako")
47 config.add_route("player_info", "/player/{id:\d+}")
48 config.add_view(player_info, route_name="player_info",
49 renderer="player_info.mako")
52 config.add_route("game_index", "/games")
53 config.add_view(game_index, route_name="game_index",
54 renderer="game_index.mako")
56 config.add_route("game_index_paged", "/games/page/{page:\d+}")
57 config.add_view(game_index, route_name="game_index_paged",
58 renderer="game_index.mako")
60 config.add_route("game_info", "/game/{id:\d+}")
61 config.add_view(game_info, route_name="game_info",
62 renderer="game_info.mako")
64 config.add_route("rank_index", "/ranks/{game_type_cd:ctf|dm|tdm|duel}")
65 config.add_view(rank_index, route_name="rank_index",
66 renderer="rank_index.mako")
68 config.add_route("rank_index_paged", "/ranks/{game_type_cd:ctf|dm|tdm|duel}/page/{page:\d+}")
69 config.add_view(rank_index, route_name="rank_index_paged",
70 renderer="rank_index.mako")
73 config.add_route("server_index_paged", "/servers/page/{page:\d+}")
74 config.add_view(server_index, route_name="server_index_paged",
75 renderer="server_index.mako")
77 config.add_route("server_index", "/servers")
78 config.add_view(server_index, route_name="server_index",
79 renderer="server_index.mako")
81 config.add_route("server_game_index",
82 "/server/{server_id:\d+}/games/page/{page:\d+}")
83 config.add_view(server_game_index, route_name="server_game_index",
84 renderer="server_game_index.mako")
86 config.add_route("server_info", "/server/{id:\d+}")
87 config.add_view(server_info, route_name="server_info",
88 renderer="server_info.mako")
91 config.add_route("map_index_paged", "/maps/page/{page:\d+}")
92 config.add_view(map_index, route_name="map_index_paged",
93 renderer="map_index.mako")
95 config.add_route("map_index", "/maps")
96 config.add_view(map_index, route_name="map_index",
97 renderer="map_index.mako")
99 config.add_route("map_info", "/map/{id:\d+}")
100 config.add_view(map_info, route_name="map_info",
101 renderer="map_info.mako")
103 config.add_route("stats_submit", "stats/submit")
104 config.add_view(stats_submit, route_name="stats_submit",
105 renderer="index.jinja2")
108 config.add_route("search", "search")
109 config.add_view(search, route_name="search",
110 renderer="search.mako")
112 config.add_route("search_paged", "search/page/{page:\d+}")
113 config.add_view(search, route_name="search_paged",
114 renderer="search.mako")
117 return config.make_wsgi_app()