]> git.xonotic.org Git - xonotic/xonstat.git/blob - xonstat/__init__.py
Fix "more games played by player <blah> page.
[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("main_index", "/")
26     config.add_view(main_index, route_name="main_index",
27         renderer="main_index.mako")
28
29     # PLAYER ROUTES
30     config.add_route("player_game_index_paged",
31             "/player/{player_id:\d+}/games/page/{page:\d+}")
32     config.add_view(player_game_index, route_name="player_game_index_paged",
33         renderer="player_game_index.mako")
34
35     config.add_route("player_game_index",
36             "/player/{player_id:\d+}/games")
37     config.add_view(player_game_index, route_name="player_game_index",
38         renderer="player_game_index.mako")
39
40     config.add_route("player_index_paged", "/players/page/{page:\d+}")
41     config.add_view(player_index, route_name="player_index_paged",
42         renderer="player_index.mako")
43
44     config.add_route("player_index", "/players")
45     config.add_view(player_index, route_name="player_index",
46         renderer="player_index.mako")
47
48     config.add_route("player_info", "/player/{id:\d+}")
49     config.add_view(player_info, route_name="player_info",
50         renderer="player_info.mako")
51
52     # GAME ROUTES
53     config.add_route("game_index", "/games")
54     config.add_view(game_index, route_name="game_index",
55         renderer="game_index.mako")
56
57     config.add_route("game_index_paged", "/games/page/{page:\d+}")
58     config.add_view(game_index, route_name="game_index_paged",
59         renderer="game_index.mako")
60
61     config.add_route("game_info", "/game/{id:\d+}")
62     config.add_view(game_info, route_name="game_info",
63         renderer="game_info.mako")
64
65     config.add_route("rank_index", "/ranks/{game_type_cd:ctf|dm|tdm|duel}")
66     config.add_view(rank_index, route_name="rank_index",
67         renderer="rank_index.mako")
68
69     config.add_route("rank_index_paged", "/ranks/{game_type_cd:ctf|dm|tdm|duel}/page/{page:\d+}")
70     config.add_view(rank_index, route_name="rank_index_paged",
71         renderer="rank_index.mako")
72
73     # SERVER ROUTES
74     config.add_route("server_index_paged", "/servers/page/{page:\d+}")
75     config.add_view(server_index, route_name="server_index_paged",
76         renderer="server_index.mako")
77
78     config.add_route("server_index", "/servers")
79     config.add_view(server_index, route_name="server_index",
80         renderer="server_index.mako")
81
82     config.add_route("server_game_index",
83         "/server/{server_id:\d+}/games/page/{page:\d+}")
84     config.add_view(server_game_index, route_name="server_game_index",
85         renderer="server_game_index.mako")
86
87     config.add_route("server_info", "/server/{id:\d+}")
88     config.add_view(server_info, route_name="server_info",
89         renderer="server_info.mako")
90
91     # MAP ROUTES
92     config.add_route("map_index_paged", "/maps/page/{page:\d+}")
93     config.add_view(map_index, route_name="map_index_paged",
94         renderer="map_index.mako")
95
96     config.add_route("map_index", "/maps")
97     config.add_view(map_index, route_name="map_index",
98         renderer="map_index.mako")
99
100     config.add_route("map_info", "/map/{id:\d+}")
101     config.add_view(map_info, route_name="map_info",
102         renderer="map_info.mako")
103
104     config.add_route("stats_submit", "stats/submit")
105     config.add_view(stats_submit, route_name="stats_submit",
106         renderer="index.jinja2")
107
108     # SEARCH ROUTES
109     config.add_route("search", "search")
110     config.add_view(search, route_name="search",
111         renderer="search.mako")
112
113     config.add_route("search_paged", "search/page/{page:\d+}")
114     config.add_view(search, route_name="search_paged",
115         renderer="search.mako")
116
117
118     return config.make_wsgi_app()