ATLAS Offline Software
Loading...
Searching...
No Matches
WebPage.htmlTable Class Reference
Collaboration diagram for WebPage.htmlTable:

Public Member Functions

 __init__ (self, tableAttr='', defaultCellAttr=[], useTableSorter=False, escapeText=False)
 __str__ (self)
 appendRow (self, cellData, rowAttr='')
 getHtml (self)

Public Attributes

 tableAttr = tableAttr
 defaultCellAttr = defaultCellAttr
 useTableSorter = useTableSorter
 escapeText = escapeText
list rows = []

Detailed Description

Make a table. Table row data is accumulated internally in a list.
   The table can be made sortable (using jQuery's plugin Tablesorter)
   by setting useTableSorter to True. Special HTML characters in cell
   data are properly replaced (using escape from cgi) if escapeText
   is set True.

Definition at line 91 of file WebPage.py.

Constructor & Destructor Documentation

◆ __init__()

WebPage.htmlTable.__init__ ( self,
tableAttr = '',
defaultCellAttr = [],
useTableSorter = False,
escapeText = False )

Definition at line 98 of file WebPage.py.

98 def __init__(self, tableAttr='', defaultCellAttr = [], useTableSorter=False, escapeText=False):
99 self.tableAttr = tableAttr
100 self.defaultCellAttr = defaultCellAttr
101 self.useTableSorter = useTableSorter
102 self.escapeText = escapeText
103 self.rows = [] # list of HTML strings with complete rows of the table
104

Member Function Documentation

◆ __str__()

WebPage.htmlTable.__str__ ( self)

Definition at line 105 of file WebPage.py.

105 def __str__(self):
106 return self.getHtml()
107

◆ appendRow()

WebPage.htmlTable.appendRow ( self,
cellData,
rowAttr = '' )
Append a row to the table. cellData is a list of the contents of
   the cells in the row. The data for each cell is either a string
   with the contents of the cell, or a tuple where the first element
   is the contents of the cell and the second element contains any
   HTML tags. Special HTML characters are properly replaced (using
   escape from cgi) if escapeText was set True when creating the
   table. If the table uses Tablesorter, <th> is used instead of
   <td> in the first row.

Definition at line 108 of file WebPage.py.

108 def appendRow(self, cellData, rowAttr=''):
109 """Append a row to the table. cellData is a list of the contents of
110 the cells in the row. The data for each cell is either a string
111 with the contents of the cell, or a tuple where the first element
112 is the contents of the cell and the second element contains any
113 HTML tags. Special HTML characters are properly replaced (using
114 escape from cgi) if escapeText was set True when creating the
115 table. If the table uses Tablesorter, <th> is used instead of
116 <td> in the first row."""
117 r = '<tr%s>\n' % sep(rowAttr)
118 if self.useTableSorter and len(self.rows)==0:
119 # First row using Tablesorter - must use <th> instead of <td>
120 cellFormat = '<th%s>%s</th>\n'
121 else:
122 cellFormat = '<td%s>%s</td>\n'
123 iCell = 0
124 for c in cellData:
125 cellAttr = self.defaultCellAttr[iCell] if iCell<len(self.defaultCellAttr) else ''
126 if isinstance(c,tuple):
127 r += cellFormat % (sep(c[1]),escape(str(c[0])) if self.escapeText else str(c[0]))
128 else:
129 r += cellFormat % (sep(cellAttr),escape(str(c)) if self.escapeText else str(c))
130 iCell += 1
131 r += '</tr>'
132 self.rows.append(r)
133

◆ getHtml()

WebPage.htmlTable.getHtml ( self)
Return the HTML code for the table.

Definition at line 134 of file WebPage.py.

134 def getHtml(self):
135 """Return the HTML code for the table."""
136 if len(self.rows)<1:
137 return ''
138 if self.useTableSorter:
139 if self.tableAttr:
140 h = '<table %s>\n' % self.tableAttr
141 else:
142 h = '<table class="tablesorter">\n'
143 h += '<thead>\n'
144 h += self.rows[0]
145 h += '\n</thead><tbody>\n'
146 h += '\n'.join(self.rows[1:])
147 h += '\n</tbody></table>\n'
148 else:
149 h = '<table%s>\n' % sep(self.tableAttr)
150 h += '\n'.join(self.rows)
151 h += '\n</table>\n'
152 return h
153

Member Data Documentation

◆ defaultCellAttr

WebPage.htmlTable.defaultCellAttr = defaultCellAttr

Definition at line 100 of file WebPage.py.

◆ escapeText

WebPage.htmlTable.escapeText = escapeText

Definition at line 102 of file WebPage.py.

◆ rows

WebPage.htmlTable.rows = []

Definition at line 103 of file WebPage.py.

◆ tableAttr

WebPage.htmlTable.tableAttr = tableAttr

Definition at line 99 of file WebPage.py.

◆ useTableSorter

WebPage.htmlTable.useTableSorter = useTableSorter

Definition at line 101 of file WebPage.py.


The documentation for this class was generated from the following file: