From 2846394dad766a59505e922868ba0c774b7ba53f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Mon, 1 Dec 2014 21:45:26 +0100 Subject: [PATCH] Introduce _buildHTML() and DisplayHTMLBlockTableWithGraph class in display.py --- display.py | 68 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 27 deletions(-) diff --git a/display.py b/display.py index 6750309..33b9f13 100644 --- a/display.py +++ b/display.py @@ -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 = '
' % (self.cssclass) if self.title: html += '
%s
' % (self.title_cssclass, self.title) html += '
%s
' % (self.value_cssclass, self.html) html += '
' - 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 = '' - if self.cols: - html += '' - 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 += '
' - self.html = html + def _buildHTML(self): + html = '' + if self.cols: + html += '' + 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 += '
' - 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):