Work for DisplayHTMLBlockTableWithGraph class
This commit is contained in:
71
display.py
71
display.py
@@ -138,20 +138,85 @@ class DisplayHTMLBlockTable(DisplayHTMLBlock):
|
||||
html += '</tr>'
|
||||
html += '</table>'
|
||||
|
||||
self.html = html
|
||||
self.html += html
|
||||
|
||||
super(DisplayHTMLBlockTable, self)._buildHTML()
|
||||
|
||||
class DisplayHTMLBlockTableWithGraph(DisplayHTMLBlockTable):
|
||||
|
||||
def __init__(self, title, cols, short_title, nb_valid_rows=0):
|
||||
def __init__(self, title, cols, short_titles=[], nb_valid_rows=0):
|
||||
super(DisplayHTMLBlockTableWithGraph, self).__init__(title=title, cols=cols)
|
||||
self.short_title = short_title
|
||||
self.short_titles = short_titles
|
||||
self.nb_valid_rows = nb_valid_rows
|
||||
# TOFIX
|
||||
self.icon_path = '/resources/icon'
|
||||
# self.icon_path = self.iwla.getConfValue('icon_path', '/')
|
||||
self.raw_rows = []
|
||||
self.maxes = [0 for c in cols]
|
||||
|
||||
def appendRow(self, row):
|
||||
self.raw_rows.append(row)
|
||||
super(DisplayHTMLBlockTableWithGraph, self).appendRow(row)
|
||||
|
||||
def appendShortTitle(self, short_title):
|
||||
self.short_titles.append(short_title)
|
||||
|
||||
def setShortTitle(self, short_titles):
|
||||
self.short_titles = short_titles
|
||||
|
||||
def setNbValidRows(self, nb_valid_rows):
|
||||
self.nb_valid_rows = nb_valid_rows
|
||||
|
||||
def _computeMax(self):
|
||||
for i in range(0, self.nb_valid_rows):
|
||||
row = self.raw_rows[i]
|
||||
for j in range(1, len(row)):
|
||||
if row[j] > self.maxes[j]:
|
||||
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'
|
||||
else: return ''
|
||||
|
||||
return '%s/%s' % (self.icon_path, icon)
|
||||
|
||||
def _buildHTML(self):
|
||||
self._computeMax()
|
||||
|
||||
html = '<table>'
|
||||
html += '<tr>'
|
||||
for i in range(0, self.nb_valid_rows):
|
||||
row = self.rows[i]
|
||||
html += '<td>'
|
||||
for j in range(1, len(row)):
|
||||
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 self.maxes[j]:
|
||||
height = int((self.raw_rows[i][j] * 100) / self.maxes[j])
|
||||
else:
|
||||
height = 0
|
||||
html += '<img%s align="bottom" src="%s" height="%d" width="6" alt="%s" title="%s" />' % (style, icon, height, alt, alt)
|
||||
html += '</td>'
|
||||
html += '</tr>'
|
||||
html += '<tr>'
|
||||
for i in range(0, len(self.short_titles)):
|
||||
style = self.getCellCSSClass(0, j)
|
||||
if style: style = ' class="%s"' % (style)
|
||||
html += '<td%s>%s</td>' % (style, self.short_titles[i])
|
||||
html += '</tr>'
|
||||
html += '</table>'
|
||||
|
||||
self.html += html
|
||||
|
||||
super(DisplayHTMLBlockTableWithGraph, self)._buildHTML()
|
||||
|
||||
class DisplayHTMLPage(object):
|
||||
|
||||
def __init__(self, title, filename, css_path):
|
||||
|
||||
Reference in New Issue
Block a user