<%inherit file="base.mako"/>
<%namespace name="nav" file="nav.mako" />
-<%namespace file="navlinks.mako" import="navlinks" />
<%block name="navigation">
${nav.nav('maps')}
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
"""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)
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,
}