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): def setRawHTML(self, html):
self.html = html self.html = html
def _buildHTML(self):
pass
def _build(self, f, html): def _build(self, f, html):
if html: f.write(html) if html: f.write(html)
def build(self, f): def build(self, f):
self._build(self.html) self._buildHTML()
self._build(f, self.html)
class DisplayHTMLBlock(DisplayHTMLRaw): class DisplayHTMLBlock(DisplayHTMLRaw):
@ -38,14 +42,14 @@ class DisplayHTMLBlock(DisplayHTMLRaw):
def setValueCSSClass(self, cssclass): def setValueCSSClass(self, cssclass):
self.value_cssclass = cssclass self.value_cssclass = cssclass
def build(self, f): def _buildHTML(self):
html = '<div class="%s">' % (self.cssclass) html = '<div class="%s">' % (self.cssclass)
if self.title: if self.title:
html += '<div class="%s">%s</div>' % (self.title_cssclass, 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 class="%s">%s</div>' % (self.value_cssclass, self.html)
html += '</div>' html += '</div>'
self._build(f, html) self.html = html
class DisplayHTMLBlockTable(DisplayHTMLBlock): class DisplayHTMLBlockTable(DisplayHTMLBlock):
@ -113,8 +117,7 @@ class DisplayHTMLBlockTable(DisplayHTMLBlock):
self.cols_cssclasses = values self.cols_cssclasses = values
def build(self, f): def _buildHTML(self):
if not self.html:
html = '<table>' html = '<table>'
if self.cols: if self.cols:
html += '<tr>' html += '<tr>'
@ -134,9 +137,20 @@ class DisplayHTMLBlockTable(DisplayHTMLBlock):
html += '<td%s>%s</td>' % (style, v) html += '<td%s>%s</td>' % (style, v)
html += '</tr>' html += '</tr>'
html += '</table>' html += '</table>'
self.html = html self.html = html
super(DisplayHTMLBlockTable, self).build(f) 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): class DisplayHTMLPage(object):