diff --git a/display.py b/display.py index 6be75df..b5a5bc0 100644 --- a/display.py +++ b/display.py @@ -48,10 +48,18 @@ class DisplayHTMLRaw(object): def _build(self, f, html): if html: f.write(html) - def build(self, f): + def build(self, f, filters=None): + if filters: self.filter(filters) self._buildHTML() self._build(f, self.html) + def _filter(self, function, **kwargs): + pass + + def filter(self, filters): + for (args, function) in filters: + self._filter(function, **args) + def getTitle(self): return '' @@ -189,6 +197,18 @@ class DisplayHTMLBlockTable(DisplayHTMLBlock): val = r[column] and int(r[column]) or 0 self.setCellValue(index, column_insertion, '%.1f%%' % (float(val*100)/float(total))) + def _filter(self, function, column, args): + target_col = None + for col in range(0, len(self.cols)): + if self.cols[col] == column: + target_col = col + break + if target_col is None: return + for row in self.rows: + res = function(row[target_col], **args) + if res: + row[target_col] = res + def _buildHTML(self): style = u'' if self.table_css: style = u' class="%s"' % (self.table_css) @@ -315,11 +335,14 @@ class DisplayHTMLPage(object): if title == b.getTitle(): return b return None - + + def getAllBlocks(self): + return self.blocks + def appendBlock(self, block): self.blocks.append(block) - def build(self, root, displayVersion=True): + def build(self, root, displayVersion=True, filters=None): filename = os.path.join(root, self.filename) base = os.path.dirname(filename) @@ -339,7 +362,7 @@ class DisplayHTMLPage(object): f.write(u'%s' % (self.title)) f.write(u'') for block in self.blocks: - block.build(f) + block.build(f, filters=filters) if displayVersion: f.write(u'
Generated by IWLA %s
' % ("http://indefero.soutade.fr/p/iwla", self.iwla.getVersion())) @@ -349,8 +372,12 @@ class DisplayHTMLPage(object): class DisplayHTMLBuild(object): def __init__(self, iwla): - self.pages = [] self.iwla = iwla + self.filters = [] + self.clear() + + def clear(self): + self.pages = [] def createPage(self, *args): return DisplayHTMLPage(self.iwla, *args) @@ -364,6 +391,9 @@ class DisplayHTMLBuild(object): return page return None + def getAllPages(self): + return self.pages + def addPage(self, page): self.pages.append(page) @@ -378,7 +408,11 @@ class DisplayHTMLBuild(object): os.symlink(target, link_name) for page in self.pages: - page.build(root) + page.build(root, filters=self.filters) + + def addColumnFilter(self, column, function, args): + self.filters.append(({'column':column, 'args':args}, function)) + # # Global functions @@ -417,4 +451,3 @@ def createCurTitle(iwla, title): if domain_name: title += u' - %s' % (domain_name) return title - diff --git a/iwla.py b/iwla.py index d6cda8e..480d2f1 100755 --- a/iwla.py +++ b/iwla.py @@ -230,7 +230,7 @@ class IWLA(object): return self.meta_infos def _clearDisplay(self): - self.display = DisplayHTMLBuild(self) + self.display.clear() return self.display def getDBFilename(self, time): diff --git a/plugins/display/track_users.py b/plugins/display/track_users.py index 8c194f7..c653e4a 100644 --- a/plugins/display/track_users.py +++ b/plugins/display/track_users.py @@ -110,7 +110,7 @@ class IWLADisplayTrackUsers(IPlugin): index = self.iwla.getDisplayIndex() - table = display.createBlock(DisplayHTMLBlockTable, title, [self.iwla._(u'IP'), self.iwla._(u'Last Access'), self.iwla._(u'Pages'), self.iwla._(u'Hits')]) + table = display.createBlock(DisplayHTMLBlockTable, title, [self.iwla._(u'Host'), self.iwla._(u'Last Access'), self.iwla._(u'Pages'), self.iwla._(u'Hits')]) table.setColsCSSClass(['', '', 'iwla_page', 'iwla_hit']) for ip in self.tracked_ip: if not ip in hits.keys(): continue