diff --git a/display.py b/display.py
index 3f5ae3c..69473a5 100644
--- a/display.py
+++ b/display.py
@@ -1,47 +1,109 @@
import os
-class DisplayHTMLBlock(object):
+class DisplayHTMLRaw(object):
- def __init__(self, title=''):
- self.title = title
-
- def build(self, f):
- pass
-
-class DisplayHTMLRawBlock(DisplayHTMLBlock):
-
- def __init__(self, title=''):
- super(DisplayHTMLRawBlock, self).__init__(title)
- self.html = ''
+ def __init__(self, html=''):
+ self.html = html
def setRawHTML(self, html):
self.html = html
+ def _build(self, f, html):
+ if html: f.write(html)
+
def build(self, f):
- f.write(self.html)
+ self._build(self.html)
+
+class DisplayHTMLBlock(DisplayHTMLRaw):
+
+ def __init__(self, title=''):
+ super(DisplayHTMLBlock, self).__init__(html='')
+ self.title = title
+ self.cssclass = 'iwla_block'
+ self.title_cssclass = 'iwla_block_title'
+ self.value_cssclass = 'iwla_block_value'
+
+ def getTitle(self):
+ return self.title
+
+ def setTitle(self, value):
+ self.title = value
+
+ def setCSSClass(self, cssclass):
+ self.cssclass = cssclass
+
+ def setTitleCSSClass(self, cssclass):
+ self.title_cssclass = cssclass
+
+ def setValueCSSClass(self, cssclass):
+ self.value_cssclass = cssclass
+
+ def build(self, f):
+ html = '
' % (self.cssclass)
+ if self.title:
+ html += '
%s
' % (self.title_cssclass, self.title)
+ html += '
%s
' % (self.value_cssclass, self.html)
+ html += '
'
+
+ self._build(f, html)
class DisplayHTMLBlockTable(DisplayHTMLBlock):
def __init__(self, title, cols):
- super(DisplayHTMLBlockTable, self).__init__(title)
+ super(DisplayHTMLBlockTable, self).__init__(title=title)
self.cols = cols
self.rows = []
+ self.cols_cssclasses = ['' for e in cols]
+ self.rows_cssclasses = []
def appendRow(self, row):
self.rows.append(listToStr(row))
+ self.rows_cssclasses.append(['' for e in row])
+ def getCellValue(row, col):
+ if row < 0 or col < 0 or\
+ row >= len(self.rows) or col >= len(self.cols):
+ raise ValueError('Invalid indices')
+
+ return self.rows[row][col]
+
+ def setCellValue(row, col, value):
+ if row < 0 or col < 0 or\
+ row >= len(self.rows) or col >= len(self.cols):
+ raise ValueError('Invalid indices')
+
+ return self.rows[row][col]
+
+ def setCellCSSClass(row, col, value):
+ if row < 0 or col < 0 or\
+ row >= len(self.rows) or col >= len(self.cols):
+ raise ValueError('Invalid indices')
+
+ self.rows_cssclasses[row][col] = value
+
+ def setRowCSSClass(row, value):
+ if row < 0 or row >= len(self.rows):
+ raise ValueError('Invalid indice')
+
+ for i in range(0, self.rows_cssclasses[row]):
+ self.rows_cssclasses[row][i] = value
+
def build(self, f):
- f.write('')
- f.write('')
- for title in self.cols:
- f.write('%s | ' % (title))
- f.write('
')
- for row in self.rows:
- f.write('')
- for v in row:
- f.write('%s | ' % (v))
- f.write('
')
- f.write('
')
+ if not self.html:
+ html = ''
+ html += ''
+ for title in self.cols:
+ html += '%s | ' % (title)
+ html += '
'
+ for row in self.rows:
+ html += ''
+ for v in row:
+ html += '%s | ' % (v)
+ html += '
'
+ html += '
'
+ self.html = html
+
+ super(DisplayHTMLBlockTable, self).build(f)
class DisplayHTMLPage(object):
@@ -53,6 +115,12 @@ class DisplayHTMLPage(object):
def getFilename(self):
return self.filename;
+ def getBlock(self, title):
+ for b in self.blocks:
+ if title == b.getTitle():
+ return b
+ return None
+
def appendBlock(self, block):
self.blocks.append(block)
@@ -64,7 +132,13 @@ class DisplayHTMLPage(object):
os.makedirs(base)
f = open(filename, 'w')
- f.write('%s' % (self.title))
+ f.write('')
+ f.write('')
+ f.write('')
+ f.write('')
+ if self.title:
+ f.write('%s' % (self.title))
+ f.write('')
for block in self.blocks:
block.build(f)
f.write('')
diff --git a/plugins/display/all_visits.py b/plugins/display/all_visits.py
index 13e160b..ea79b0f 100644
--- a/plugins/display/all_visits.py
+++ b/plugins/display/all_visits.py
@@ -42,6 +42,11 @@ class IWLADisplayAllVisits(IPlugin):
display.addPage(page)
index = self.iwla.getDisplayIndex()
- block = DisplayHTMLRawBlock()
- block.setRawHTML('All visits' % (filename))
- index.appendBlock(block)
+ link = 'All visits' % (filename)
+ block = index.getBlock('Top visitors')
+ if block:
+ block.setTitle('%s - %s' % (block.getTitle(), link))
+ else:
+ block = DisplayHTMLRawBlock()
+ block.setRawHTML(link)
+ index.appendBlock(block)
diff --git a/plugins/display/referers.py b/plugins/display/referers.py
index 06a87c0..128026c 100644
--- a/plugins/display/referers.py
+++ b/plugins/display/referers.py
@@ -29,29 +29,10 @@ class IWLADisplayReferers(IPlugin):
top_key_phrases = key_phrases.items()
top_key_phrases = sorted(top_key_phrases, key=lambda t: t[1], reverse=True)
- # Top referers in index
+ cur_time = self.iwla.getCurTime()
index = self.iwla.getDisplayIndex()
- table = DisplayHTMLBlockTable('Connexion from', ['Origin', 'Pages', 'Hits'])
- table.appendRow(['Search Engine', '', ''])
- for r,_ in top_search_engine_referers[:10]:
- row = [r, search_engine_referers[r]['pages'], search_engine_referers[r]['hits']]
- table.appendRow(row)
-
- table.appendRow(['External URL', '', ''])
- for r,_ in top_referers[:10]:
- row = [r, referers[r]['pages'], referers[r]['hits']]
- table.appendRow(row)
-
- table.appendRow(['External URL (robot)', '', ''])
- for r,_ in top_robots_referers[:10]:
- row = [r, robots_referers[r]['pages'], robots_referers[r]['hits']]
- table.appendRow(row)
-
- index.appendBlock(table)
-
# All referers in a file
- cur_time = self.iwla.getCurTime()
title = time.strftime('Connexion from - %B %Y', cur_time)
filename = 'referers.html'
@@ -80,14 +61,27 @@ class IWLADisplayReferers(IPlugin):
display = self.iwla.getDisplay()
display.addPage(page)
- block = DisplayHTMLRawBlock()
- block.setRawHTML('All referers' % (filename))
- index.appendBlock(block)
+ link = 'All referers' % (filename)
+
+ # Top referers in index
+ title = '%s - %s' % ('Connexion from', link)
+
+ table = DisplayHTMLBlockTable(title, ['Origin', 'Pages', 'Hits'])
+ table.appendRow(['Search Engine', '', ''])
+ for r,_ in top_search_engine_referers[:10]:
+ row = [r, search_engine_referers[r]['pages'], search_engine_referers[r]['hits']]
+ table.appendRow(row)
+
+ table.appendRow(['External URL', '', ''])
+ for r,_ in top_referers[:10]:
+ row = [r, referers[r]['pages'], referers[r]['hits']]
+ table.appendRow(row)
+
+ table.appendRow(['External URL (robot)', '', ''])
+ for r,_ in top_robots_referers[:10]:
+ row = [r, robots_referers[r]['pages'], robots_referers[r]['hits']]
+ table.appendRow(row)
- # Top key phrases in index
- table = DisplayHTMLBlockTable('Top key phrases', ['Key phrase', 'Search'])
- for phrase in top_key_phrases[:10]:
- table.appendRow([phrase[0], phrase[1]])
index.appendBlock(table)
# All key phrases in a file
@@ -104,6 +98,11 @@ class IWLADisplayReferers(IPlugin):
display.addPage(page)
- block = DisplayHTMLRawBlock()
- block.setRawHTML('All key phrases' % (filename))
- index.appendBlock(block)
+ link = 'All key phrases' % (filename)
+
+ # Top key phrases in index
+ title = '%s - %s' % ('Top key phrases', link)
+ table = DisplayHTMLBlockTable(title, ['Key phrase', '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 efe92d3..5ca8e9e 100644
--- a/plugins/display/top_downloads.py
+++ b/plugins/display/top_downloads.py
@@ -12,20 +12,12 @@ class IWLADisplayTopDownloads(IPlugin):
def hook(self):
top_downloads = self.iwla.getMonthStats()['top_downloads']
-
top_downloads = sorted(top_downloads.items(), key=lambda t: t[1], reverse=True)
- index = self.iwla.getDisplayIndex()
-
- table = DisplayHTMLBlockTable('Top Downloads', ['URI', 'Hits'])
- for (uri, entrance) in top_downloads[:10]:
- table.appendRow([uri, entrance])
- index.appendBlock(table)
-
- title = time.strftime('Top Downloads - %B %Y', self.iwla.getCurTime())
-
+ # All in a file
filename = 'top_downloads.html'
path = self.iwla.getCurDisplayPath(filename)
+ title = time.strftime('All Downloads - %B %Y', self.iwla.getCurTime())
page = DisplayHTMLPage(title, path)
table = DisplayHTMLBlockTable('All Downloads', ['URI', 'Hit'])
@@ -33,9 +25,15 @@ class IWLADisplayTopDownloads(IPlugin):
table.appendRow([uri, entrance])
page.appendBlock(table)
- display = self.iwla.getDisplay()
- display.addPage(page)
+ self.iwla.getDisplay().addPage(page)
- block = DisplayHTMLRawBlock()
- block.setRawHTML('All Downloads' % (filename))
- index.appendBlock(block)
+ link = 'All Downloads' % (filename)
+ title = '%s - %s' % ('Top Downloads', link)
+
+ # Top in index
+ index = self.iwla.getDisplayIndex()
+
+ table = DisplayHTMLBlockTable(title, ['URI', 'Hits'])
+ 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 e196de9..1e44259 100644
--- a/plugins/display/top_hits.py
+++ b/plugins/display/top_hits.py
@@ -12,30 +12,28 @@ class IWLADisplayTopHits(IPlugin):
def hook(self):
top_hits = self.iwla.getMonthStats()['top_hits']
-
top_hits = sorted(top_hits.items(), key=lambda t: t[1], reverse=True)
- index = self.iwla.getDisplayIndex()
-
- table = DisplayHTMLBlockTable('Top Hits', ['URI', 'Entrance'])
- for (uri, entrance) in top_hits[:10]:
- table.appendRow([uri, entrance])
- index.appendBlock(table)
-
+ # All in a file
title = time.strftime('All Hits - %B %Y', self.iwla.getCurTime())
-
filename = 'top_hits.html'
path = self.iwla.getCurDisplayPath(filename)
page = DisplayHTMLPage(title, path)
- table = DisplayHTMLBlockTable('Top Hits', ['URI', 'Entrance'])
+ table = DisplayHTMLBlockTable('All Hits', ['URI', 'Entrance'])
for (uri, entrance) in top_hits:
table.appendRow([uri, entrance])
page.appendBlock(table)
- display = self.iwla.getDisplay()
- display.addPage(page)
+ self.iwla.getDisplay().addPage(page)
- block = DisplayHTMLRawBlock()
- block.setRawHTML('All hits' % (filename))
- index.appendBlock(block)
+ link = 'All hits' % (filename)
+ title = '%s - %s' % ('Top Hits', link)
+
+ # Top in index
+ index = self.iwla.getDisplayIndex()
+
+ table = DisplayHTMLBlockTable(title, ['URI', 'Entrance'])
+ 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 ddd68b9..3c3cfee 100644
--- a/plugins/display/top_pages.py
+++ b/plugins/display/top_pages.py
@@ -12,30 +12,28 @@ class IWLADisplayTopPages(IPlugin):
def hook(self):
top_pages = self.iwla.getMonthStats()['top_pages']
-
top_pages = sorted(top_pages.items(), key=lambda t: t[1], reverse=True)
- index = self.iwla.getDisplayIndex()
-
- table = DisplayHTMLBlockTable('Top Pages', ['URI', 'Entrance'])
- for (uri, entrance) in top_pages[:10]:
- table.appendRow([uri, entrance])
- index.appendBlock(table)
-
+ # All in a page
title = time.strftime('All Pages - %B %Y', self.iwla.getCurTime())
-
filename = 'top_pages.html'
path = self.iwla.getCurDisplayPath(filename)
page = DisplayHTMLPage(title, path)
- table = DisplayHTMLBlockTable('Top Pages', ['URI', 'Entrance'])
+ table = DisplayHTMLBlockTable('All Pages', ['URI', 'Entrance'])
for (uri, entrance) in top_pages:
table.appendRow([uri, entrance])
page.appendBlock(table)
- display = self.iwla.getDisplay()
- display.addPage(page)
+ self.iwla.getDisplay().addPage(page)
- block = DisplayHTMLRawBlock()
- block.setRawHTML('All pages' % (filename))
- index.appendBlock(block)
+ link = 'All pages' % (filename)
+ title = '%s - %s' % ('Top Pages', link)
+
+ # Top in index
+ index = self.iwla.getDisplayIndex()
+
+ table = DisplayHTMLBlockTable(title, ['URI', 'Entrance'])
+ for (uri, entrance) in top_pages[:10]:
+ table.appendRow([uri, entrance])
+ index.appendBlock(table)