Browse Source

properly handle log retrieval in the model and add filtering functionality

Natenom/support-murmur-13-1446181288462
Michael Ziegler 15 years ago
parent
commit
ad87dbed82
  1. 6
      pyweb/mumble/models.py
  2. 22
      pyweb/mumble/templates/mumble/mumble.html
  3. 4
      pyweb/mumble/views.py

6
pyweb/mumble/models.py

@ -553,6 +553,12 @@ class Mumble( models.Model ):
def banUser( self, sessionid, reason="" ): def banUser( self, sessionid, reason="" ):
return self.ctl.addBanForSession( self.srvid, sessionid, reason=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="" ): def mk_registration_property( field, doc="" ):

22
pyweb/mumble/templates/mumble/mumble.html

@ -240,10 +240,28 @@
width: 500, width: 500,
dataIndex: 'txt' 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({ store: new Ext.data.DirectStore({
baseParams: {'server': 1, 'start': 0, 'limit': 100},
baseParams: {'server': 1, 'start': 0, 'limit': 100, 'filter': ''},
directFn: Mumble.log, directFn: Mumble.log,
paramOrder: ['server', 'start', 'limit'],
paramOrder: ['server', 'start', 'limit', 'filter'],
paramsNames: { paramsNames: {
start: 'start', start: 'start',
limit: 'limit', limit: 'limit',

4
pyweb/mumble/views.py

@ -207,14 +207,14 @@ def get_admin( request, server ):
@login_required @login_required
@EXT_DIRECT_PROVIDER.register_method( "Mumble" ) @EXT_DIRECT_PROVIDER.register_method( "Mumble" )
def log( request, server, start, limit ):
def log( request, server, start, limit, filter ):
""" Retrieve log messages. """ """ Retrieve log messages. """
srv = get_object_or_404( Mumble, id=int(server) ) srv = get_object_or_404( Mumble, id=int(server) )
if not srv.isUserAdmin( request.user ): if not srv.isUserAdmin( request.user ):
raise Exception( "Access denied" ) raise Exception( "Access denied" )
return { 'data': [ return { 'data': [
{ 'timestamp': ent.timestamp, 'txt': ent.txt } { '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 } ], 'success': True }

Loading…
Cancel
Save