From ad87dbed82d2cbf4d46ac9dcb248558d6247fa51 Mon Sep 17 00:00:00 2001 From: Michael Ziegler Date: Fri, 30 Jul 2010 18:24:24 +0200 Subject: [PATCH] properly handle log retrieval in the model and add filtering functionality --- pyweb/mumble/models.py | 6 ++++++ pyweb/mumble/templates/mumble/mumble.html | 22 ++++++++++++++++++++-- pyweb/mumble/views.py | 4 ++-- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/pyweb/mumble/models.py b/pyweb/mumble/models.py index 9fd019e..e5dc3fd 100644 --- a/pyweb/mumble/models.py +++ b/pyweb/mumble/models.py @@ -553,6 +553,12 @@ class Mumble( models.Model ): def banUser( self, sessionid, reason="" ): return self.ctl.addBanForSession( self.srvid, sessionid, reason=reason ) + def getLog( self, first=0, last=100, filter="" ): + """ Return log entries from ``first`` to ``last`` that contain ``filter`` (if any). """ + logentries = self.ctl.getLog( self.srvid, first, last ) + if not filter: + return logentries + return [ logentry for logentry in logentries if filter in logentry.txt ] def mk_registration_property( field, doc="" ): diff --git a/pyweb/mumble/templates/mumble/mumble.html b/pyweb/mumble/templates/mumble/mumble.html index c42fb9f..1c680f4 100644 --- a/pyweb/mumble/templates/mumble/mumble.html +++ b/pyweb/mumble/templates/mumble/mumble.html @@ -240,10 +240,28 @@ width: 500, dataIndex: 'txt' }]), + bbar: [{ text: gettext('Filter') + ':' }, { + xtype: 'textfield', + name: 'filter', + listeners: { + render: function(c) { + Ext.QuickTips.register({ + target: c.getEl(), + text: gettext('Enter a string to filter the logs by and press Enter. To display all log entries, empty this field.') + }); + }, + specialkey: function( field, ev ){ + if( ev.getKey() == ev.ENTER ){ + field.ownerCt.ownerCt.store.baseParams.filter = field.getValue(); + field.ownerCt.ownerCt.store.reload(); + } + } + }, + }], store: new Ext.data.DirectStore({ - baseParams: {'server': 1, 'start': 0, 'limit': 100}, + baseParams: {'server': 1, 'start': 0, 'limit': 100, 'filter': ''}, directFn: Mumble.log, - paramOrder: ['server', 'start', 'limit'], + paramOrder: ['server', 'start', 'limit', 'filter'], paramsNames: { start: 'start', limit: 'limit', diff --git a/pyweb/mumble/views.py b/pyweb/mumble/views.py index 97ff32e..be5e4d7 100644 --- a/pyweb/mumble/views.py +++ b/pyweb/mumble/views.py @@ -207,14 +207,14 @@ def get_admin( request, server ): @login_required @EXT_DIRECT_PROVIDER.register_method( "Mumble" ) -def log( request, server, start, limit ): +def log( request, server, start, limit, filter ): """ Retrieve log messages. """ srv = get_object_or_404( Mumble, id=int(server) ) if not srv.isUserAdmin( request.user ): raise Exception( "Access denied" ) return { 'data': [ { 'timestamp': ent.timestamp, 'txt': ent.txt } - for ent in srv.ctl.getLog( srv.srvid, start, (start + limit) ) + for ent in srv.getLog( start, (start + limit), filter ) ], 'success': True }