]> git.xonotic.org Git - xonotic/xonstat.git/blob - xonstat/__init__.py
Add ranks view based on game type.
[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_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")
34
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")
38
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")
42
43     config.add_route("player_index", "/players")
44     config.add_view(player_index, route_name="player_index",
45         renderer="player_index.mako")
46
47     config.add_route("player_info", "/player/{id:\d+}")
48     config.add_view(player_info, route_name="player_info",
49         renderer="player_info.mako")
50
51     # GAME ROUTES
52     config.add_route("game_index", "/games")
53     config.add_view(game_index, route_name="game_index",
54         renderer="game_index.mako")
55
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")
59
60     config.add_route("game_info", "/game/{id:\d+}")
61     config.add_view(game_info, route_name="game_info",
62         renderer="game_info.mako")
63
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")
67
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")
71
72     # SERVER ROUTES
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")
76
77     config.add_route("server_index", "/servers")
78     config.add_view(server_index, route_name="server_index",
79         renderer="server_index.mako")
80
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")
85
86     config.add_route("server_info", "/server/{id:\d+}")
87     config.add_view(server_info, route_name="server_info",
88         renderer="server_info.mako")
89
90     # MAP ROUTES
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")
94
95     config.add_route("map_index", "/maps")
96     config.add_view(map_index, route_name="map_index",
97         renderer="map_index.mako")
98
99     config.add_route("map_info", "/map/{id:\d+}")
100     config.add_view(map_info, route_name="map_info",
101         renderer="map_info.mako")
102
103     config.add_route("stats_submit", "stats/submit")
104     config.add_view(stats_submit, route_name="stats_submit",
105         renderer="index.jinja2")
106
107     # SEARCH ROUTES
108     config.add_route("search", "search")
109     config.add_view(search, route_name="search",
110         renderer="search.mako")
111
112     config.add_route("search_paged", "search/page/{page:\d+}")
113     config.add_view(search, route_name="search_paged",
114         renderer="search.mako")
115
116
117     return config.make_wsgi_app()