2019-04-26 21:21:50 +02:00
|
|
|
# See LICENSE for licensing information.
|
|
|
|
|
#
|
2022-11-30 23:50:43 +01:00
|
|
|
# Copyright (c) 2016-2022 Regents of the University of California and The Board
|
2019-06-14 17:43:41 +02:00
|
|
|
# of Regents for the Oklahoma Agricultural and Mechanical College
|
|
|
|
|
# (acting for and on behalf of Oklahoma State University)
|
|
|
|
|
# All rights reserved.
|
2019-04-26 21:21:50 +02:00
|
|
|
#
|
2022-07-13 19:57:56 +02:00
|
|
|
|
2019-01-09 15:15:22 +01:00
|
|
|
class table_gen:
|
2019-02-07 15:33:39 +01:00
|
|
|
"""small library of functions to generate the html tables"""
|
|
|
|
|
|
|
|
|
|
def __init__(self, name):
|
2019-01-09 15:15:22 +01:00
|
|
|
self.name = name
|
|
|
|
|
self.rows = []
|
|
|
|
|
self.table_id = 'data'
|
|
|
|
|
|
2019-02-07 15:33:39 +01:00
|
|
|
def add_row(self, row):
|
|
|
|
|
"""add a row to table_gen object"""
|
2019-01-09 15:15:22 +01:00
|
|
|
self.rows.append(row)
|
|
|
|
|
|
|
|
|
|
def gen_table_head(self):
|
2019-02-07 15:33:39 +01:00
|
|
|
"""generate html table header"""
|
2019-01-09 15:15:22 +01:00
|
|
|
html = ''
|
|
|
|
|
|
|
|
|
|
html += '<thead>'
|
|
|
|
|
html += '<tr>'
|
|
|
|
|
for col in self.rows[0]:
|
2019-02-07 15:33:39 +01:00
|
|
|
html += '<th>' + str(col) + '</th>'
|
2019-01-09 15:15:22 +01:00
|
|
|
html += '</tr>'
|
|
|
|
|
html += '</thead>'
|
|
|
|
|
return html
|
|
|
|
|
|
2019-03-07 05:59:52 +01:00
|
|
|
def gen_table_body(self,comments):
|
2019-02-07 15:33:39 +01:00
|
|
|
"""generate html body (used after gen_table_head)"""
|
2019-01-09 15:15:22 +01:00
|
|
|
html = ''
|
|
|
|
|
|
|
|
|
|
html += '<tbody>'
|
|
|
|
|
html += '<tr>'
|
|
|
|
|
for row in self.rows[1:]:
|
2019-03-07 05:59:52 +01:00
|
|
|
|
|
|
|
|
if row[0] not in comments:
|
|
|
|
|
html += '<tr>'
|
|
|
|
|
for col in row:
|
|
|
|
|
html += '<td>' + str(col) + '</td>'
|
|
|
|
|
html += '</tr>'
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
html += '<!--'+row[0]+'<tr>'
|
|
|
|
|
for col in row:
|
|
|
|
|
html += '<td>' + str(col) + '</td>'
|
2019-03-07 07:20:07 +01:00
|
|
|
html += '</tr>'+row[0]+'-->'
|
2019-03-07 05:59:52 +01:00
|
|
|
|
2019-01-09 15:15:22 +01:00
|
|
|
html += '</tr>'
|
|
|
|
|
html += '</tbody>'
|
|
|
|
|
return html
|
2019-03-07 06:12:21 +01:00
|
|
|
def sort(self):
|
|
|
|
|
self.rows[1:] = sorted(self.rows[1:], key=lambda x : x[0])
|
2019-02-07 15:33:39 +01:00
|
|
|
|
2019-03-07 05:59:52 +01:00
|
|
|
def to_html(self,comments):
|
2019-02-07 15:33:39 +01:00
|
|
|
"""writes table_gen object to inline html"""
|
2019-01-09 15:15:22 +01:00
|
|
|
html = ''
|
|
|
|
|
html += '<table id= \"'+self.table_id+'\">'
|
|
|
|
|
html += self.gen_table_head()
|
2019-03-07 05:59:52 +01:00
|
|
|
html += self.gen_table_body(comments)
|
|
|
|
|
html += '</table>\n'
|
2019-02-07 15:33:39 +01:00
|
|
|
|
2019-01-09 15:15:22 +01:00
|
|
|
return html
|