from xonstat.views import *
from xonstat.security import *
+
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
config.add_view(game_finder_json, route_name="game_index_json", renderer="jsonp")
# SERVER ROUTES
- config.add_route("server_index", "/servers")
- config.add_view(server_index, route_name="server_index", renderer="server_index.mako")
-
- config.add_route("server_index_json", "/servers.json")
- config.add_view(server_index_json, route_name="server_index_json", renderer="jsonp")
+ config.add_route("server_index", "/servers")
+ config.add_view(
+ view=ServerIndex,
+ route_name="server_index",
+ attr="html",
+ renderer="server_index.mako",
+ accept="text/html"
+ )
+ config.add_view(
+ view=ServerIndex,
+ route_name="server_index",
+ attr="json",
+ renderer="json",
+ accept="text/json"
+ )
config.add_route("server_info", "/server/{id:\d+}")
config.add_view(server_info, route_name="server_info", renderer="server_info.mako")
from xonstat.views.map import map_info_json, map_index_json
from xonstat.views.map import map_captimes, map_captimes_json
-from xonstat.views.server import server_info, server_index
-from xonstat.views.server import server_info_json
-from xonstat.views.server import server_index_json
+from xonstat.views.server import server_info, server_info_json
+from xonstat.views.server import ServerIndex
from xonstat.views.search import search_q, search
from xonstat.views.search import search_json
log = logging.getLogger(__name__)
-def _server_index_data(request):
- if request.params.has_key('page'):
- current_page = request.params['page']
- else:
- current_page = 1
- try:
- server_q = DBSession.query(Server).\
- order_by(Server.server_id.desc())
-
- servers = Page(server_q, current_page, items_per_page=25, url=page_url)
+class ServerIndex(object):
+ def __init__(self, request):
+ self.request = request
+ self.page = request.params.get("page", 1)
+ self.servers = self._data()
- except Exception as e:
- servers = None
+ def _data(self):
+ try:
+ server_q = DBSession.query(Server).order_by(Server.server_id.desc())
+ servers = Page(server_q, self.page, items_per_page=25, url=page_url)
- return {'servers':servers, }
+ except:
+ servers = None
+ return servers
-def server_index(request):
- """
- Provides a list of all the current servers.
- """
- return _server_index_data(request)
+ def html(self):
+ return {
+ 'servers': self.servers,
+ }
-
-def server_index_json(request):
- """
- Provides a list of all the current servers. JSON.
- """
- return [{'status':'not implemented'}]
+ def json(self):
+ return {
+ 'servers': [s.to_dict() for s in self.servers],
+ }
def _server_info_data(request):