From a6c8a756f70e97337d8a77e29c0b0de6322a1301 Mon Sep 17 00:00:00 2001 From: Patrick Speiser Date: Fri, 28 Sep 2012 18:00:36 +0200 Subject: [PATCH] Changed Logs page to use ajax for retrieving log messages as needed instead of getting all at the start and freezing the browser --- data/interfaces/default/logs.html | 56 ++++++++++++++++--------------- headphones/webserve.py | 32 ++++++++++++++++++ 2 files changed, 61 insertions(+), 27 deletions(-) diff --git a/data/interfaces/default/logs.html b/data/interfaces/default/logs.html index 022be43e..84bdc1f9 100644 --- a/data/interfaces/default/logs.html +++ b/data/interfaces/default/logs.html @@ -16,21 +16,6 @@ lossless<%inherit file="base.html"/> - %for line in lineList: - <% - timestamp, message, level, threadname = line - - if level == 'WARNING' or level == 'ERROR': - grade = 'X' - else: - grade = 'Z' - %> - - ${timestamp} - ${level} - ${message} - - %endfor @@ -42,22 +27,39 @@ lossless<%inherit file="base.html"/> <%def name="javascriptIncludes()"> \ No newline at end of file diff --git a/headphones/webserve.py b/headphones/webserve.py index 799d84f3..59718b9e 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -394,6 +394,38 @@ class WebInterface(object): return serve_template(templatename="logs.html", title="Log", lineList=headphones.LOG_LIST) logs.exposed = True + + def getLog(self,iDisplayStart=0,iDisplayLength=100,iSortCol_0=0,iSortCol_1=0,iSortCol_2=0, + sSortDir_0="desc",sSortDir_1="desc",sSortDir_2="desc", + sSearch="",**kwargs): + + iDisplayStart = int(iDisplayStart) + iDisplayLength = int(iDisplayLength) + + filtered = [] + if sSearch == "": + filtered = headphones.LOG_LIST[::] + else: + filtered = [row for row in headphones.LOG_LIST for column in row if sSearch in column] + + sortcolumn = 0 + if iSortCol_0 == '1': + sortcolumn = 2 + elif iSortCol_0 == '2': + sortcolumn = 1 + filtered.sort(key=lambda x:x[sortcolumn],reverse=sSortDir_0 == "desc") + + rows = filtered[iDisplayStart:(iDisplayStart+iDisplayLength)] + rows = [[row[0],row[2],row[1]] for row in rows] + + dict = {'iTotalDisplayRecords':len(filtered), + 'iTotalRecords':len(headphones.LOG_LIST), + 'aaData':rows, + } + s = simplejson.dumps(dict) + return s + getLog.exposed = True + def clearhistory(self, type=None): myDB = db.DBConnection() if type == 'all':