changeset 78:6f524697f79d

Implemented paging to admin user acion log
author Marcin Kuzminski <marcin@python-blog.com>
date Sat, 17 Apr 2010 19:07:29 +0200
parents e2600310e0b2
children 9fe23fdab9e9
files pylons_app/controllers/admin.py pylons_app/templates/admin.html
diffstat 2 files changed, 9 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/pylons_app/controllers/admin.py	Wed Apr 14 00:51:23 2010 +0200
+++ b/pylons_app/controllers/admin.py	Sat Apr 17 19:07:29 2010 +0200
@@ -14,6 +14,7 @@
 import formencode.htmlfill as htmlfill
 from pylons_app.model import meta
 from pylons_app.model.db import Users, UserLogs
+from webhelpers.paginate import Page
 log = logging.getLogger(__name__)
 
 class AdminController(BaseController):
@@ -53,8 +54,11 @@
                 )
         if c.admin_user:
             sa = meta.Session
-            c.users_log = sa.query(UserLogs)\
-                .order_by(UserLogs.action_date.desc()).limit(10).all()
+                             
+            users_log = sa.query(UserLogs)\
+                .order_by(UserLogs.action_date.desc())
+            p = int(request.params.get('page', 1))
+            c.users_log = Page(users_log, page=p, items_per_page=10)
         return render('/admin.html')
 
     def hgrc(self, dirname):
--- a/pylons_app/templates/admin.html	Wed Apr 14 00:51:23 2010 +0200
+++ b/pylons_app/templates/admin.html	Sat Apr 17 19:07:29 2010 +0200
@@ -51,6 +51,9 @@
 					<td>${l.action_date}</td>
 				</tr>
 			%endfor
+			<tr>
+				<td>${c.users_log.pager('$link_previous ~2~ $link_next')}</td>
+			</tr>
 			</table>        
 		%else:
 			${_('No actions yet')}