]> de.git.xonotic.org Git - xonotic/xonstat.git/commitdiff
Use pagination on the maps page instead of a full select count(*).
authorAnt Zucaro <azucaro@gmail.com>
Sun, 18 Dec 2016 23:25:37 +0000 (18:25 -0500)
committerAnt Zucaro <azucaro@gmail.com>
Sun, 18 Dec 2016 23:25:37 +0000 (18:25 -0500)
xonstat/templates/map_index.mako
xonstat/views/map.py

index 481b9a8d292ed00536f3b8ac4889b5907b4ddc30..0dc12111a158713f42d396921f7bc5368715dfbb 100644 (file)
@@ -1,6 +1,5 @@
 <%inherit file="base.mako"/>
 <%namespace name="nav" file="nav.mako" />
-<%namespace file="navlinks.mako" import="navlinks" />
 
 <%block name="navigation">
   ${nav.nav('maps')}
@@ -10,8 +9,11 @@
   Map Index
 </%block>
 
-% if not maps:
-  <h2>Sorry, no maps yet. Get playing!</h2>
+% if not maps and last is not None:
+  <h2 class="text-center">Sorry, no more maps!</h2>
+
+% elif not maps:
+  <h2 class="text-center">Sorry, no maps yet. Get playing!</h2>
 
 % else:
   <div class="row">
       % endfor
       </table>
 
-      <!-- navigation links -->
-      ${navlinks("map_index", maps.page, maps.last_page)}
+      % if len(maps) == 20:
+        <div class="row">
+          <div class="small-12 columns">
+            <ul class="pagination">
+              <li>
+                <a  href="${request.route_url('map_index', _query=query)}" name="Next Page">Next <i class="fa fa-arrow-right"></i></a>
+              </li>
+            </ul>
+          </div>
+        </div>
+      % endif
+
     </div> <!-- /span4 -->
   </div> <!-- /row -->
 % endif
index f1daf4aabe7f57c385ce1a0a1511fa9fe8e22773..ccc1529652295899a241e66efe62150cc5e3e8b1 100644 (file)
@@ -24,15 +24,21 @@ class MapIndex(object):
         """Common parameter parsing."""
         self.request = request
         self.page = request.params.get("page", 1)
+        self.last = request.params.get("last", None)
 
-        # all views share this data, so we'll precalculate
+        # all views share this data, so we'll pre-calculate
         self.maps = self.map_index()
 
     def map_index(self):
         """Returns the raw data shared by all renderers."""
         try:
-            map_q = DBSession.query(Map).order_by(Map.map_id.desc())
-            maps = Page(map_q, self.page, items_per_page=INDEX_COUNT, url=page_url)
+            map_q = DBSession.query(Map)
+
+            if self.last:
+                map_q = map_q.filter(Map.map_id < self.last)
+
+            map_q = map_q.order_by(Map.map_id.desc()).limit(INDEX_COUNT)
+            maps = map_q.all()
 
         except Exception as e:
             log.debug(e)
@@ -42,14 +48,21 @@ class MapIndex(object):
 
     def html(self):
         """For rendering this data using something HTML-based."""
+        # build the query string
+        query = {}
+        if len(self.maps) > 1:
+            query['last'] = self.maps[-1].map_id
+
         return {
             'maps': self.maps,
+            'query': query,
         }
 
     def json(self):
         """For rendering this data using JSON."""
         return {
             'maps': [m.to_dict() for m in self.maps],
+            'last': self.last,
         }