Separate display functions into display.py
This commit is contained in:
40
display.py
Normal file
40
display.py
Normal file
@@ -0,0 +1,40 @@
|
||||
def createPage(display, filename, title):
|
||||
page = {}
|
||||
page['title'] = title;
|
||||
page['blocks'] = []
|
||||
display[filename] = page
|
||||
|
||||
return page
|
||||
|
||||
def appendBlockToPage(page, block):
|
||||
page['blocks'].append(block)
|
||||
|
||||
def createTable(title, cols):
|
||||
table = {'type' : 'table', 'title' : title}
|
||||
table['cols'] = cols
|
||||
table['rows'] = []
|
||||
|
||||
def appendRowToTable(table, row):
|
||||
table['rows'].append(row)
|
||||
|
||||
def buildPages(display):
|
||||
for filename in display.keys():
|
||||
page = display[filename]
|
||||
with open(DISPLAY_ROOT + filename, 'w') as f:
|
||||
f.write('<html><title>%s</title><body>' % (page['title']))
|
||||
for block in page['blocks']:
|
||||
if block['type'] == 'html':
|
||||
f.write(block['value'])
|
||||
elif block['type'] == 'table':
|
||||
f.write('<table>')
|
||||
f.write('<tr>')
|
||||
for title in block['cols']:
|
||||
f.write('<th>%s</th>' % (title))
|
||||
f.write('</tr>')
|
||||
for row in block['rows']:
|
||||
f.write('<tr>')
|
||||
for v in row:
|
||||
f.write('<td>%s</td>' % (v))
|
||||
f.write('</tr>')
|
||||
f.write('</table>')
|
||||
f.write('</body></html>')
|
||||
Reference in New Issue
Block a user