]> git.xonotic.org Git - xonotic/xonstat.git/blob - xonstat/__init__.py
clean dangling commit on actually merged branch
[xonotic/xonstat.git] / xonstat / __init__.py
1 import sqlahelper
2 from pyramid.config import Configurator
3 from sqlalchemy import engine_from_config
4 from xonstat.models import initialize_db
5 from xonstat.views import * 
6
7 def main(global_config, **settings):
8     """ This function returns a Pyramid WSGI application.
9     """
10     # setup the database engine
11     engine = engine_from_config(settings, 'sqlalchemy.')
12     sqlahelper.add_engine(engine)
13
14     # initialize database structures
15     initialize_db(engine)
16
17     config = Configurator(settings=settings)
18
19     config.add_static_view('static', 'xonstat:static')
20
21     # ROOT ROUTE
22     config.add_route("main_index", "/")
23     config.add_view(main_index, route_name="main_index",
24         renderer="main_index.mako")
25
26     # MAIN SUBMISSION ROUTE
27     config.add_route("stats_submit", "stats/submit")
28     config.add_view(stats_submit, route_name="stats_submit")
29
30     # PLAYER ROUTES
31     config.add_route("player_game_index_paged",
32             "/player/{player_id:\d+}/games/page/{page:\d+}")
33     config.add_view(player_game_index, route_name="player_game_index_paged",
34         renderer="player_game_index.mako")
35
36     config.add_route("player_game_index",
37             "/player/{player_id:\d+}/games")
38     config.add_view(player_game_index, route_name="player_game_index",
39         renderer="player_game_index.mako")
40
41     config.add_route("player_index_paged", "/players/page/{page:\d+}")
42     config.add_view(player_index, route_name="player_index_paged",
43         renderer="player_index.mako")
44
45     config.add_route("player_index", "/players")
46     config.add_view(player_index, route_name="player_index",
47         renderer="player_index.mako")
48
49     config.add_route("player_info", "/player/{id:\d+}")
50     config.add_view(player_info, route_name="player_info",
51         renderer="player_info.mako")
52
53     config.add_route("player_accuracy", "/player/{id:\d+}/accuracy")
54     config.add_view(player_accuracy, route_name="player_accuracy",
55         renderer="json")
56
57     # GAME ROUTES
58     config.add_route("game_index", "/games")
59     config.add_view(game_index, route_name="game_index",
60         renderer="game_index.mako")
61
62     config.add_route("game_index_paged", "/games/page/{page:\d+}")
63     config.add_view(game_index, route_name="game_index_paged",
64         renderer="game_index.mako")
65
66     config.add_route("game_info", "/game/{id:\d+}")
67     config.add_view(game_info, route_name="game_info",
68         renderer="game_info.mako")
69
70     config.add_route("rank_index", "/ranks/{game_type_cd:ctf|dm|tdm|duel}")
71     config.add_view(rank_index, route_name="rank_index",
72         renderer="rank_index.mako")
73
74     config.add_route("rank_index_paged", "/ranks/{game_type_cd:ctf|dm|tdm|duel}/page/{page:\d+}")
75     config.add_view(rank_index, route_name="rank_index_paged",
76         renderer="rank_index.mako")
77
78     # SERVER ROUTES
79     config.add_route("server_index_paged", "/servers/page/{page:\d+}")
80     config.add_view(server_index, route_name="server_index_paged",
81         renderer="server_index.mako")
82
83     config.add_route("server_index", "/servers")
84     config.add_view(server_index, route_name="server_index",
85         renderer="server_index.mako")
86
87     config.add_route("server_game_index",
88         "/server/{server_id:\d+}/games/page/{page:\d+}")
89     config.add_view(server_game_index, route_name="server_game_index",
90         renderer="server_game_index.mako")
91
92     config.add_route("server_info", "/server/{id:\d+}")
93     config.add_view(server_info, route_name="server_info",
94         renderer="server_info.mako")
95
96     # MAP ROUTES
97     config.add_route("map_index_paged", "/maps/page/{page:\d+}")
98     config.add_view(map_index, route_name="map_index_paged",
99         renderer="map_index.mako")
100
101     config.add_route("map_index", "/maps")
102     config.add_view(map_index, route_name="map_index",
103         renderer="map_index.mako")
104
105     config.add_route("map_info", "/map/{id:\d+}")
106     config.add_view(map_info, route_name="map_info",
107         renderer="map_info.mako")
108
109     # SEARCH ROUTES
110     config.add_route("search", "search")
111     config.add_view(search, route_name="search",
112         renderer="search.mako")
113
114     config.add_route("search_paged", "search/page/{page:\d+}")
115     config.add_view(search, route_name="search_paged",
116         renderer="search.mako")
117
118
119     return config.make_wsgi_app()