diff --git a/display.py b/display.py
index febb705..bb14313 100644
--- a/display.py
+++ b/display.py
@@ -1,8 +1,9 @@
import os
+import codecs
class DisplayHTMLRaw(object):
- def __init__(self, html=''):
+ def __init__(self, html=u''):
self.html = html
def setRawHTML(self, html):
@@ -23,31 +24,31 @@ 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'
+ self.cssclass = u'iwla_block'
+ self.title_cssclass = u'iwla_block_title'
+ self.value_cssclass = u'iwla_block_value'
def getTitle(self):
return self.title
def setTitle(self, value):
- self.title = value
+ self.title = unicode(value)
def setCSSClass(self, cssclass):
- self.cssclass = cssclass
+ self.cssclass = unicode(cssclass)
def setTitleCSSClass(self, cssclass):
- self.title_cssclass = cssclass
+ self.title_cssclass = unicode(cssclass)
def setValueCSSClass(self, cssclass):
- self.value_cssclass = cssclass
+ self.value_cssclass = unicode(cssclass)
def _buildHTML(self):
- html = '
' % (self.cssclass)
+ html = u'
' % (self.cssclass)
if self.title:
- html += '
%s
' % (self.title_cssclass, self.title)
- html += '
%s
' % (self.value_cssclass, self.html)
- html += '
'
+ html += u'
%s
' % (self.title_cssclass, self.title)
+ html += u'
%s
' % (self.value_cssclass, self.html)
+ html += u'
'
self.html = html
@@ -55,15 +56,15 @@ class DisplayHTMLBlockTable(DisplayHTMLBlock):
def __init__(self, title, cols):
super(DisplayHTMLBlockTable, self).__init__(title=title)
- self.cols = cols
+ self.cols = listToStr(cols)
self.rows = []
- self.cols_cssclasses = [''] * len(cols)
+ self.cols_cssclasses = [u''] * len(cols)
self.rows_cssclasses = []
- self.table_css = 'iwla_table'
+ self.table_css = u'iwla_table'
def appendRow(self, row):
self.rows.append(listToStr(row))
- self.rows_cssclasses.append([''] * len(row))
+ self.rows_cssclasses.append([u''] * len(row))
def getCellValue(self, row, col):
if row < 0 or col < 0 or\
@@ -77,14 +78,14 @@ class DisplayHTMLBlockTable(DisplayHTMLBlock):
row >= len(self.rows) or col >= len(self.cols):
raise ValueError('Invalid indices %d,%d' % (row, col))
- self.rows[row][col] = value
+ self.rows[row][col] = unicode(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 %d,%d' % (row, col))
- self.rows_cssclasses[row][col] = value
+ self.rows_cssclasses[row][col] = unicode(value)
def getCellCSSClass(self, row, col):
if row < 0 or col < 0 or\
@@ -103,42 +104,42 @@ class DisplayHTMLBlockTable(DisplayHTMLBlock):
if row < 0 or row >= len(self.rows):
raise ValueError('Invalid indice %d' % (row))
- self.rows_cssclasses[row] = [value] * len(self.rows_cssclasses[row])
+ self.rows_cssclasses[row] = [unicode(value)] * len(self.rows_cssclasses[row])
def setColCSSClass(self, col, value):
if col < 0 or col >= len(self.cols):
raise ValueError('Invalid indice %d' % (col))
- self.cols_cssclasses[col] = value
+ self.cols_cssclasses[col] = unicode(value)
def setColsCSSClass(self, values):
if len(values) != len(self.cols):
raise ValueError('Invalid values size')
- self.cols_cssclasses = values
+ self.cols_cssclasses = [unicode(values)] * len(self.cols)
def _buildHTML(self):
- style = ''
- if self.table_css: style = ' class="%s"' % (self.table_css)
- html = '' % (style)
+ style = u''
+ if self.table_css: style = u' class="%s"' % (self.table_css)
+ html = u'' % (style)
if self.cols:
- html += ''
+ html += u'
'
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 += '
'
+ if style: style = u' class="%s"' % (style)
+ html += u'%s | ' % (style, title)
+ html += u''
for i in range(0, len(self.rows)):
row = self.rows[i]
- html += ''
+ html += u'
'
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 += '
'
+ if style: style = u' class="%s"' % (style)
+ html += u'%s | ' % (style, v)
+ html += u''
+ html += u'
'
self.html += html
@@ -149,14 +150,15 @@ class DisplayHTMLBlockTableWithGraph(DisplayHTMLBlockTable):
def __init__(self, title, cols, short_titles=None, nb_valid_rows=0, graph_cols=None):
super(DisplayHTMLBlockTableWithGraph, self).__init__(title=title, cols=cols)
self.short_titles = short_titles or []
+ self.short_titles = listToStr(self.short_titles)
self.nb_valid_rows = nb_valid_rows
# TOFIX
- self.icon_path = 'resources/icon'
+ self.icon_path = u'resources/icon'
# self.icon_path = self.iwla.getConfValue('icon_path', '/')
self.raw_rows = []
self.maxes = [0] * len(cols)
- self.table_graph_css = 'iwla_graph_table'
- self.td_img_css = 'iwla_td_img'
+ self.table_graph_css = u'iwla_graph_table'
+ self.td_img_css = u'iwla_td_img'
self.graph_cols = graph_cols or []
def appendRow(self, row):
@@ -164,10 +166,10 @@ class DisplayHTMLBlockTableWithGraph(DisplayHTMLBlockTable):
super(DisplayHTMLBlockTableWithGraph, self).appendRow(row)
def appendShortTitle(self, short_title):
- self.short_titles.append(short_title)
+ self.short_titles.append(unicode(short_title))
def setShortTitle(self, short_titles):
- self.short_titles = short_titles
+ self.short_titles = listToStr(short_titles)
def setNbValidRows(self, nb_valid_rows):
self.nb_valid_rows = nb_valid_rows
@@ -180,47 +182,47 @@ class DisplayHTMLBlockTableWithGraph(DisplayHTMLBlockTable):
self.maxes[j] = row[j]
def _getIconFromStyle(self, style):
- if style.startswith('iwla_page'): icon = 'vp.png'
- elif style.startswith('iwla_hit'): icon = 'vh.png'
- elif style.startswith('iwla_bandwidth'): icon = 'vk.png'
- elif style.startswith('iwla_visit'): icon = 'vv.png'
- elif style.startswith('iwla_search'): icon = 'vu.png'
+ if style.startswith(u'iwla_page'): icon = u'vp.png'
+ elif style.startswith(u'iwla_hit'): icon = u'vh.png'
+ elif style.startswith(u'iwla_bandwidth'): icon = u'vk.png'
+ elif style.startswith(u'iwla_visitor'): icon = u'vu.png'
+ elif style.startswith(u'iwla_visit'): icon = u'vv.png'
else: return ''
- return '%s/%s' % (self.icon_path, icon)
+ return u'%s/%s' % (self.icon_path, icon)
def _buildHTML(self):
self._computeMax()
- style = ''
- if self.table_graph_css: style = ' class="%s"' % (self.table_graph_css)
- html = '' % (style)
- html += ''
+ style = u''
+ if self.table_graph_css: style = u' class="%s"' % (self.table_graph_css)
+ html = u'' % (style)
+ html += u''
for i in range(0, self.nb_valid_rows):
row = self.rows[i]
- css = ''
- if self.td_img_css: css=' class="%s"' % (self.td_img_css)
- html += '' % (css)
+ css = u''
+ if self.td_img_css: css=u' class="%s"' % (self.td_img_css)
+ html += u' | ' % (css)
for j in self.graph_cols:
style = self.getColCSSClass(j)
icon = self._getIconFromStyle(style)
if not icon: continue
- if style: style = ' class="%s"' % (style)
- alt = '%s: %s' % (row[j], self.cols[j])
+ if style: style = u' class="%s"' % (style)
+ alt = u'%s: %s' % (row[j], self.cols[j])
if self.maxes[j]:
height = int((self.raw_rows[i][j] * 100) / self.maxes[j]) or 1
else:
height = 1
- html += '' % (style, icon, height, alt, alt)
- html += ' | '
- html += '
'
- html += ''
+ html += u'' % (style, icon, height, alt, alt)
+ html += u''
+ html += u'
'
+ html += u''
for i in range(0, len(self.short_titles)):
style = self.getCellCSSClass(i, 0)
- if style: style = ' class="%s"' % (style)
- html += '%s | ' % (style, self.short_titles[i])
- html += '
'
- html += '
'
+ if style: style = u' class="%s"' % (style)
+ html += u'%s | ' % (style, self.short_titles[i])
+ html += u'
'
+ html += u'
'
self.html += html
@@ -229,10 +231,10 @@ class DisplayHTMLBlockTableWithGraph(DisplayHTMLBlockTable):
class DisplayHTMLPage(object):
def __init__(self, title, filename, css_path):
- self.title = title
+ self.title = unicode(title)
self.filename = filename
self.blocks = []
- self.css_path = css_path
+ self.css_path = listToStr(css_path)
def getFilename(self):
return self.filename;
@@ -253,19 +255,19 @@ class DisplayHTMLPage(object):
if not os.path.exists(base):
os.makedirs(base)
- f = open(filename, 'w')
- f.write('')
- f.write('')
- f.write('')
- f.write('')
+ f = codecs.open(filename, 'w', 'utf-8')
+ f.write(u'')
+ f.write(u'')
+ f.write(u'')
+ f.write(u'')
for css in self.css_path:
- f.write('' % (css))
+ f.write(u'' % (css))
if self.title:
- f.write('%s' % (self.title))
- f.write('')
+ f.write(u'%s' % (self.title))
+ f.write(u'')
for block in self.blocks:
block.build(f)
- f.write('')
+ f.write(u'