else:
return strip_colors(self.nick)
+ def joined_pretty_date(self):
+ return pretty_date(self.create_dt)
+
def __repr__(self):
return "<Player(%s, %s)>" % (self.player_id,
self.nick.encode('utf-8'))
text-align:center;
}
+/* pagination */
+.pagination {
+ padding-right: 8px;
+}
+
+
/* drop-down navigation */
.nav, .nav ul {
list-style: none;
% for player in players:\r
<tr>\r
<td><a href="${request.route_url("player_info", id=player.player_id)}" title="Go to this player's info page">${player.nick_html_colors()|n}</a></th>\r
- <td>${player.create_dt.strftime('%m/%d/%Y at %H:%M')}</th>\r
+ <td>${player.joined_pretty_date()}</th>\r
</tr>\r
% endfor\r
</table>\r
% endif\r
\r
+<!-- pagination -->\r
+<a class="pagination" href="${request.route_url("player_index_paged", page=1)}" name="First Page"><<</a>\r
+\r
% if players.previous_page:\r
-<a href="${request.route_url("player_index_paged", page=players.previous_page)}" name="Previous Page">Previous</a>\r
+<a class="pagination" href="${request.route_url("player_index_paged", page=players.previous_page)}" name="Previous Page"><</a>\r
% endif\r
+\r
+% for page in pages_to_link:\r
+<a class="pagination" href="${request.route_url("player_index_paged", page=page)}" name="Go to page ${page}">${page}</a>\r
+% endfor\r
+\r
% if players.next_page:\r
-<a href="${request.route_url("player_index_paged", page=players.next_page)}" name="Next Page">Next</a>\r
+<a class="pagination" href="${request.route_url("player_index_paged", page=players.next_page)}" name="Next Page">></a>\r
% endif\r
+\r
+<a class="pagination" href="${request.route_url("player_index_paged", page=players.last_page)}" name="Last Page">>></a>\r
+\r
+(Page <a href="${request.route_url("player_index_paged", page=players.page)}" name="Go to page ${players.page}">${players.page}</a> of <a href="${request.route_url("player_index_paged", page=players.last_page)}" name="Last Page">${players.last_page}</a>)\r
import datetime\r
import logging\r
import re\r
+import sqlalchemy as sa\r
import time\r
from pyramid.response import Response\r
+from pyramid.url import current_route_url\r
from sqlalchemy import desc\r
from webhelpers.paginate import Page, PageURL\r
from xonstat.models import *\r
Provides a list of all the current players. \r
"""\r
if 'page' in request.matchdict:\r
- current_page = request.matchdict['page']\r
+ current_page = int(request.matchdict['page'])\r
else:\r
current_page = 1\r
\r
try:\r
player_q = DBSession.query(Player).\\r
filter(Player.player_id > 2).\\r
+ filter(sa.not_(Player.nick.like('Anonymous Player%'))).\\r
order_by(Player.player_id.desc())\r
\r
players = Page(player_q, current_page, url=page_url)\r
\r
- \r
+ last_linked_page = current_page + 4\r
+ if last_linked_page > players.last_page:\r
+ last_linked_page = players.last_page\r
+\r
+ pages_to_link = range(current_page+1, last_linked_page+1)\r
+\r
except Exception as e:\r
players = None\r
+ raise e\r
\r
- return {'players':players, }\r
+ return {'players':players,\r
+ 'pages_to_link':pages_to_link,\r
+ }\r
\r
\r
def player_info(request):\r