Changeset - 6f524697f79d
[Not reviewed]
default
0 2 0
Marcin Kuzminski - 16 years ago 2010-04-17 19:07:29
marcin@python-blog.com
Implemented paging to admin user acion log
2 files changed with 9 insertions and 2 deletions:
0 comments (0 inline, 0 general)
pylons_app/controllers/admin.py
Show inline comments
 
@@ -5,24 +5,25 @@ from pylons.controllers.util import abor
 

	
 
from pylons_app.lib.base import BaseController, render
 
import os
 
from mercurial import ui, hg
 
from mercurial.error import RepoError
 
from ConfigParser import ConfigParser
 
from pylons_app.lib import auth
 
from pylons_app.model.forms import LoginForm
 
import formencode
 
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):
 

	
 
    def __before__(self):
 
        c.staticurl = g.statics
 
        c.admin_user = session.get('admin_user', False)
 
        c.admin_username = session.get('admin_username')
 
        
 
    def index(self):
 
        # Return a rendered template
 
        if request.POST:
 
@@ -44,26 +45,29 @@ class AdminController(BaseController):
 
            except formencode.Invalid, error:
 
                c.form_result = error.value
 
                c.form_errors = error.error_dict or {}
 
                html = render('/admin.html')
 

	
 
                return htmlfill.render(
 
                    html,
 
                    defaults=c.form_result,
 
                    encoding="UTF-8"
 
                )
 
        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):
 
        filename = os.path.join(dirname, '.hg', 'hgrc')
 
        return filename
 

	
 
    def add_repo(self, new_repo):
 
        
 

	
 
        #extra check it can be add since it's the command
 
        if new_repo == '_admin':
 
            c.msg = 'DENIED'
pylons_app/templates/admin.html
Show inline comments
 
@@ -42,24 +42,27 @@
 
	        	<td>${_('Repository')}</td>
 
	        	<td>${_('Action')}</td>
 
	        	<td>${_('Date')}</td>
 
	        </tr>
 
	        %for cnt,l in enumerate(c.users_log):
 
				<tr class="parity${cnt%2}">
 
					<td>${l.user.username}</td>
 
					<td>${l.repository}</td>
 
					<td>${l.action}</td>
 
					<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')}
 
		%endif
 

	
 
    </div>
 
    %else:
 
        <div>
 
        <br />
 
        <h2>${_('Login')}</h2>
 
        ${h.form(h.url.current())}
 
        <table>
0 comments (0 inline, 0 general)