Introduce _buildHTML() and DisplayHTMLBlockTableWithGraph class in display.py

This commit is contained in:
Grégory Soutadé 2014-12-01 21:45:26 +01:00
parent 5d6362105b
commit 2846394dad

View File

@ -8,11 +8,15 @@ class DisplayHTMLRaw(object):
def setRawHTML(self, html):
self.html = html
def _buildHTML(self):
pass
def _build(self, f, html):
if html: f.write(html)
def build(self, f):
self._build(self.html)
self._buildHTML()
self._build(f, self.html)
class DisplayHTMLBlock(DisplayHTMLRaw):
@ -38,14 +42,14 @@ class DisplayHTMLBlock(DisplayHTMLRaw):
def setValueCSSClass(self, cssclass):
self.value_cssclass = cssclass
def build(self, f):
def _buildHTML(self):
html = '<div class="%s">' % (self.cssclass)
if self.title:
html += '<div class="%s">%s</div>' % (self.title_cssclass, self.title)
html += '<div class="%s">%s</div>' % (self.value_cssclass, self.html)
html += '</div>'
self._build(f, html)
self.html = html
class DisplayHTMLBlockTable(DisplayHTMLBlock):
@ -113,30 +117,40 @@ class DisplayHTMLBlockTable(DisplayHTMLBlock):
self.cols_cssclasses = values
def build(self, f):
if not self.html:
html = '<table>'
if self.cols:
html += '<tr>'
for i in range (0, len(self.cols)):
title = self.cols[i]
style = self.getColCSSClass(i)
if style: style = ' class="%s"' % (style)
html += '<th%s>%s</th>' % (style, title)
html += '</tr>'
for i in range(0, len(self.rows)):
row = self.rows[i]
html += '<tr>'
for j in range(0, len(row)):
v = row[j]
style = self.getCellCSSClass(i, j)
if style: style = ' class="%s"' % (style)
html += '<td%s>%s</td>' % (style, v)
html += '</tr>'
html += '</table>'
self.html = html
def _buildHTML(self):
html = '<table>'
if self.cols:
html += '<tr>'
for i in range (0, len(self.cols)):
title = self.cols[i]
style = self.getColCSSClass(i)
if style: style = ' class="%s"' % (style)
html += '<th%s>%s</th>' % (style, title)
html += '</tr>'
for i in range(0, len(self.rows)):
row = self.rows[i]
html += '<tr>'
for j in range(0, len(row)):
v = row[j]
style = self.getCellCSSClass(i, j)
if style: style = ' class="%s"' % (style)
html += '<td%s>%s</td>' % (style, v)
html += '</tr>'
html += '</table>'
super(DisplayHTMLBlockTable, self).build(f)
self.html = html
super(DisplayHTMLBlockTable, self)._buildHTML()
class DisplayHTMLBlockTableWithGraph(DisplayHTMLBlockTable):
def __init__(self, title, cols, short_title, nb_valid_rows=0):
super(DisplayHTMLBlockTableWithGraph, self).__init__(title=title, cols=cols)
self.short_title = short_title
self.nb_valid_rows = nb_valid_rows
def setNbValidRows(self, nb_valid_rows):
self.nb_valid_rows = nb_valid_rows
class DisplayHTMLPage(object):