diff --git a/display.py b/display.py index 69473a5..c119712 100644 --- a/display.py +++ b/display.py @@ -60,45 +60,78 @@ class DisplayHTMLBlockTable(DisplayHTMLBlock): self.rows.append(listToStr(row)) self.rows_cssclasses.append(['' for e in row]) - def getCellValue(row, col): + def getCellValue(self, row, col): if row < 0 or col < 0 or\ row >= len(self.rows) or col >= len(self.cols): - raise ValueError('Invalid indices') + raise ValueError('Invalid indices %d,%d' % (row, col)) return self.rows[row][col] - def setCellValue(row, col, value): + def setCellValue(self, row, col, value): if row < 0 or col < 0 or\ row >= len(self.rows) or col >= len(self.cols): - raise ValueError('Invalid indices') + raise ValueError('Invalid indices %d,%d' % (row, col)) return self.rows[row][col] - def setCellCSSClass(row, col, value): + def setCellCSSClass(self, row, col, value): if row < 0 or col < 0 or\ row >= len(self.rows) or col >= len(self.cols): - raise ValueError('Invalid indices') + raise ValueError('Invalid indices %d,%d' % (row, col)) self.rows_cssclasses[row][col] = value - def setRowCSSClass(row, value): + def getCellCSSClass(self, row, col): + if row < 0 or col < 0 or\ + row >= len(self.rows) or col >= len(self.cols): + raise ValueError('Invalid indices %d,%d' % (row, col)) + + return self.rows_cssclasses[row][col] + + def getColCSSClass(self, col): + if col < 0 or col >= len(self.cols): + raise ValueError('Invalid indice %d' % (col)) + + return self.cols_cssclasses[col] + + def setRowCSSClass(self, row, value): if row < 0 or row >= len(self.rows): - raise ValueError('Invalid indice') + raise ValueError('Invalid indice %d' % (row)) for i in range(0, self.rows_cssclasses[row]): self.rows_cssclasses[row][i] = value - + + def setColCSSClass(self, col, value): + if col < 0 or col >= len(self.cols): + raise ValueError('Invalid indice %d' % (col)) + + self.cols_cssclasses[col] = value + + def setColsCSSClass(self, values): + if len(values) != len(self.cols): + raise ValueError('Invalid values size') + + self.cols_cssclasses = values + def build(self, f): if not self.html: html = '' - html += '' - for title in self.cols: - html += '' % (title) - html += '' - for row in self.rows: + if self.cols: html += '' - for v in row: - html += '' % (v) + for i in range (0, len(self.cols)): + title = self.cols[i] + style = self.getColCSSClass(i) + if style: style = ' class="%s"' % (style) + html += '%s' % (style, title) + html += '' + for i in range(0, len(self.rows)): + row = self.rows[i] + html += '' + for j in range(0, len(row)): + v = row[j] + style = self.getCellCSSClass(i, j) + if style: style = ' class="%s"' % (style) + html += '%s' % (style, v) html += '' html += '
%s
%s
' self.html = html diff --git a/iwla.py b/iwla.py index 2f01132..f9e9d62 100755 --- a/iwla.py +++ b/iwla.py @@ -232,7 +232,7 @@ class IWLA(object): page = DisplayHTMLPage(title, filename) days = DisplayHTMLBlockTable('By day', ['Day', 'Visits', 'Pages', 'Hits', 'Bandwidth', 'Not viewed Bandwidth']) - + days.setColsCSSClass(['', 'iwla_visit', 'iwla_page', 'iwla_hit', 'iwla_bandwith', 'iwla_bandwith']) keys = self.current_analysis['days_stats'].keys() keys.sort() nb_visits = 0 diff --git a/plugins/display/all_visits.py b/plugins/display/all_visits.py index ea79b0f..2e643f5 100644 --- a/plugins/display/all_visits.py +++ b/plugins/display/all_visits.py @@ -22,6 +22,8 @@ class IWLADisplayAllVisits(IPlugin): page = DisplayHTMLPage(title, path) table = DisplayHTMLBlockTable('Last seen', ['Host', 'Pages', 'Hits', 'Bandwidth', 'Last seen']) + table.setColsCSSClass(['', 'iwla_page', 'iwla_hit', 'iwla_bandwith', '']) + for super_hit in last_access: address = super_hit['remote_addr'] if display_visitor_ip and\ diff --git a/plugins/display/referers.py b/plugins/display/referers.py index 128026c..60bc154 100644 --- a/plugins/display/referers.py +++ b/plugins/display/referers.py @@ -40,7 +40,8 @@ class IWLADisplayReferers(IPlugin): page = DisplayHTMLPage(title, path) table = DisplayHTMLBlockTable('Connexion from', ['Origin', 'Pages', 'Hits']) - + table.setColsCSSClass(['', 'iwla_page', 'iwla_hit']) + table.appendRow(['Search Engine', '', '']) for r,_ in top_search_engine_referers: row = [r, search_engine_referers[r]['pages'], search_engine_referers[r]['hits']] @@ -67,6 +68,8 @@ class IWLADisplayReferers(IPlugin): title = '%s - %s' % ('Connexion from', link) table = DisplayHTMLBlockTable(title, ['Origin', 'Pages', 'Hits']) + table.setColsCSSClass(['', 'iwla_page', 'iwla_hit']) + table.appendRow(['Search Engine', '', '']) for r,_ in top_search_engine_referers[:10]: row = [r, search_engine_referers[r]['pages'], search_engine_referers[r]['hits']] @@ -92,6 +95,7 @@ class IWLADisplayReferers(IPlugin): page = DisplayHTMLPage(title, path) table = DisplayHTMLBlockTable('Top key phrases', ['Key phrase', 'Search']) + table.setColsCSSClass(['', 'iwla_search']) for phrase in top_key_phrases: table.appendRow([phrase[0], phrase[1]]) page.appendBlock(table) @@ -103,6 +107,7 @@ class IWLADisplayReferers(IPlugin): # Top key phrases in index title = '%s - %s' % ('Top key phrases', link) table = DisplayHTMLBlockTable(title, ['Key phrase', 'Search']) + table.setColsCSSClass(['', 'iwla_search']) for phrase in top_key_phrases[:10]: table.appendRow([phrase[0], phrase[1]]) index.appendBlock(table) diff --git a/plugins/display/top_downloads.py b/plugins/display/top_downloads.py index 5ca8e9e..727c138 100644 --- a/plugins/display/top_downloads.py +++ b/plugins/display/top_downloads.py @@ -20,7 +20,8 @@ class IWLADisplayTopDownloads(IPlugin): title = time.strftime('All Downloads - %B %Y', self.iwla.getCurTime()) page = DisplayHTMLPage(title, path) - table = DisplayHTMLBlockTable('All Downloads', ['URI', 'Hit']) + table = DisplayHTMLBlockTable('All Downloads', ['URI', 'Hit']) + table.setColsCSSClass(['', 'iwla_hit']) for (uri, entrance) in top_downloads: table.appendRow([uri, entrance]) page.appendBlock(table) @@ -33,7 +34,8 @@ class IWLADisplayTopDownloads(IPlugin): # Top in index index = self.iwla.getDisplayIndex() - table = DisplayHTMLBlockTable(title, ['URI', 'Hits']) + table = DisplayHTMLBlockTable(title, ['URI', 'Hits']) + table.setColsCSSClass(['', 'iwla_hit']) for (uri, entrance) in top_downloads[:10]: table.appendRow([uri, entrance]) index.appendBlock(table) diff --git a/plugins/display/top_hits.py b/plugins/display/top_hits.py index 1e44259..9beecd1 100644 --- a/plugins/display/top_hits.py +++ b/plugins/display/top_hits.py @@ -21,6 +21,7 @@ class IWLADisplayTopHits(IPlugin): page = DisplayHTMLPage(title, path) table = DisplayHTMLBlockTable('All Hits', ['URI', 'Entrance']) + table.setColsCSSClass(['', 'iwla_hit']) for (uri, entrance) in top_hits: table.appendRow([uri, entrance]) page.appendBlock(table) @@ -34,6 +35,7 @@ class IWLADisplayTopHits(IPlugin): index = self.iwla.getDisplayIndex() table = DisplayHTMLBlockTable(title, ['URI', 'Entrance']) + table.setColsCSSClass(['', 'iwla_hit']) for (uri, entrance) in top_hits[:10]: table.appendRow([uri, entrance]) index.appendBlock(table) diff --git a/plugins/display/top_pages.py b/plugins/display/top_pages.py index 3c3cfee..bf7c907 100644 --- a/plugins/display/top_pages.py +++ b/plugins/display/top_pages.py @@ -20,7 +20,8 @@ class IWLADisplayTopPages(IPlugin): path = self.iwla.getCurDisplayPath(filename) page = DisplayHTMLPage(title, path) - table = DisplayHTMLBlockTable('All Pages', ['URI', 'Entrance']) + table = DisplayHTMLBlockTable('All Pages', ['URI', 'Entrance']) + table.setColsCSSClass(['', 'iwla_hit']) for (uri, entrance) in top_pages: table.appendRow([uri, entrance]) page.appendBlock(table) @@ -33,7 +34,8 @@ class IWLADisplayTopPages(IPlugin): # Top in index index = self.iwla.getDisplayIndex() - table = DisplayHTMLBlockTable(title, ['URI', 'Entrance']) + table = DisplayHTMLBlockTable(title, ['URI', 'Entrance']) + table.setColsCSSClass(['', 'iwla_hit']) for (uri, entrance) in top_pages[:10]: table.appendRow([uri, entrance]) index.appendBlock(table) diff --git a/plugins/display/top_visitors.py b/plugins/display/top_visitors.py index e806209..8748f27 100644 --- a/plugins/display/top_visitors.py +++ b/plugins/display/top_visitors.py @@ -21,6 +21,7 @@ class IWLADisplayTopVisitors(IPlugin): index = self.iwla.getDisplayIndex() table = DisplayHTMLBlockTable('Top visitors', ['Host', 'Pages', 'Hits', 'Bandwidth', 'Last seen']) + table.setColsCSSClass(['', 'iwla_page', 'iwla_hit', 'iwla_bandwith', '']) for super_hit in top_visitors: address = super_hit['remote_addr'] if display_visitor_ip and\