Create a map index view and corresponding template.
authorAnt Zucaro <azucaro@gmail.com>
Fri, 24 Jun 2011 20:20:23 +0000 (16:20 -0400)
committerAnt Zucaro <azucaro@gmail.com>
Fri, 24 Jun 2011 20:20:23 +0000 (16:20 -0400)
xonstat/__init__.py
xonstat/templates/base.mako
xonstat/templates/map_index.mako [new file with mode: 0755]
xonstat/views/__init__.py
xonstat/views/map.py

index fa91e50a5f872eb411e38f4b6d2b06ed5192cca4..06337537d0f1505373deaaf99ddbec0e27acdc7e 100755 (executable)
@@ -63,6 +63,13 @@ def main(global_config, **settings):
             renderer='server_info.mako') 
 
     # MAP ROUTES
+    config.add_route(name="map_index_paged", 
+            pattern="/maps/page/{page:\d+}", view=map_index, 
+            renderer='map_index.mako') 
+
+    config.add_route(name="map_index", pattern="/maps", view=map_index, 
+            renderer='map_index.mako') 
+
     config.add_route(name="map_info", pattern="/map/{id:\d+}", view=map_info, 
             renderer='map_info.mako') 
 
index 76b6dc04c8a47b4b4935b448c337a159e45e8a38..812ec31c845df7abcb09c2efcd96bc537a7d0807 100755 (executable)
@@ -18,7 +18,7 @@
             <ul id="nav">
                 <li><a href="/players" title="Player Index">players</a></li>
                 <li><a href="/games" title="Game Index">games</a></li>
-                <li><a href="" title="Map Index">maps</a></li>
+                <li><a href="/maps" title="Map Index">maps</a></li>
                 <li><a href="" title="Server Index">servers</a></li>
             </ul>
         </div> <!-- END HEADER -->
diff --git a/xonstat/templates/map_index.mako b/xonstat/templates/map_index.mako
new file mode 100755 (executable)
index 0000000..ad47b60
--- /dev/null
@@ -0,0 +1,31 @@
+<%inherit file="base.mako"/>\r
+\r
+<%block name="title">\r
+Map Index - ${parent.title()}\r
+</%block>\r
+\r
+% if not maps:\r
+<h2>Sorry, no maps yet. Get playing!</h2>\r
+\r
+% else:\r
+<h2>Map Index</h2>\r
+<table border="1">\r
+  <tr>\r
+    <th>#</th>\r
+    <th>Name</th>\r
+  </tr>\r
+% for map in maps:\r
+  <tr>\r
+    <td>${map.map_id}</th>\r
+    <td><a href="${request.route_url("map_info", id=map.map_id)}" title="Go to this map's info page">${map.name}</a></th>\r
+  </tr>\r
+% endfor\r
+</table>\r
+% endif\r
+\r
+% if maps.previous_page:\r
+<a href="${request.route_url("map_index_paged", page=maps.previous_page)}" name="Previous Page">Previous</a>\r
+% endif\r
+% if maps.next_page:\r
+<a href="${request.route_url("map_index_paged", page=maps.next_page)}" name="Next Page">Next</a>\r
+% endif\r
index 229b7f9f55f9f65d53c32bd1cfbbc641df262021..c9fd80de3462a9a4fc314b30538bcd12c4ac239e 100755 (executable)
@@ -1,6 +1,6 @@
 from xonstat.views.submission import stats_submit\r
 from xonstat.views.player import player_index, player_info, player_game_index\r
 from xonstat.views.game import game_index, game_info\r
-from xonstat.views.map import map_info\r
+from xonstat.views.map import map_info, map_index\r
 from xonstat.views.server import server_info, server_game_index\r
 from xonstat.views.main import main_index\r
index 358dc5f8fdb43cb030f56580b020929a0bdc5d1c..aca27d619f5acb27eb6c53b99d44a9ab4076a150 100755 (executable)
@@ -6,6 +6,27 @@ from xonstat.util import page_url
 \r
 log = logging.getLogger(__name__)\r
 \r
+def map_index(request):\r
+    """\r
+    Provides a list of all the current maps. \r
+    """\r
+    if 'page' in request.matchdict:\r
+        current_page = request.matchdict['page']\r
+    else:\r
+        current_page = 1\r
+\r
+    try:\r
+        map_q = DBSession.query(Map).\\r
+                order_by(Map.name)\r
+\r
+        maps = Page(map_q, current_page, url=page_url)\r
+\r
+        \r
+    except Exception as e:\r
+        maps = None\r
+\r
+    return {'maps':maps, }\r
+\r
 \r
 def map_info(request):\r
     """\r