def _make_table(self, context, fields, rows, **atts): table = BaseElement('table', bgcolor='MediumOrchid3', **atts) table.context = context self._add_table_header(table, fields + ['command']) for row in rows: self._add_table_row(table, fields, row) return table
def __init__(self, fields, idcol, action, record, **atts): BaseElement.__init__(self, 'table', **atts) self.record = record refdata = None if hasattr(record, '_refdata'): refdata = record._refdata for field in fields: row = BaseElement('tr') key = TD(bgcolor='DarkSeaGreen') key.appendChild(Bold(field)) row.appendChild(key) val = TD() if refdata is not None and field in refdata.cols: ridcol = refdata.cols[field] refrec = refdata.data[field][record[ridcol]] node = refdata.object[field](refrec) if action: url = '.'.join(map(str, [action, field, record[idcol]])) val.appendChild(Anchor(url, node)) else: val.appendChild(node) elif action: url = '.'.join(map(str, [action, field, record[idcol]])) val.appendChild(Anchor(url, record[field])) else: node = Text() node.data = record[field] val.appendChild(node) row.appendChild(val) self.val = val self.key = key self.appendChild(row)
def _add_table_header(self, table, fields, **atts): th = BaseElement('th', **atts) trow = TR() th.appendChild(trow) for field in fields: trow.appendChild(TxtTD(Bold(field))) table.appendChild(th) table.header = th
def set_machine(self, machine): self.machine.set_machine(machine) self.clear_body() title = SimpleTitleElement('Machine: %s' % machine, bgcolor='IndianRed', width='100%') self.body.appendChild(title) mtable = BaseElement('table') for k,v in self.machine.current.items(): trow = TR() trow.appendChild(TxtTD(Bold(k))) trow.appendChild(TxtTD(v)) mtable.appendChild(trow) self.body.appendChild(mtable) self.body.appendChild(SectionTitle('Machine Type')) self.body.appendChild(SectionTitle('Kernel')) self.body.appendChild(SectionTitle('Profile')) self.body.appendChild(SectionTitle('Filesystem'))
def set_machine(self, machine): self.machine.set_machine(machine) self.clear_body() title = SimpleTitleElement('Machine: %s' % machine, bgcolor='IndianRed', width='100%') self.body.appendChild(title) mtable = BaseElement('table') for k, v in self.machine.current.items(): trow = TR() trow.appendChild(TxtTD(Bold(k))) trow.appendChild(TxtTD(v)) mtable.appendChild(trow) self.body.appendChild(mtable) newanchor = Anchor('new.machine.foo', 'new') editanchor = Anchor('edit.machine.%s' % machine, 'edit') self.body.appendChild(HR()) self.body.appendChild(editanchor) self.body.appendChild(BR()) self.body.appendChild(newanchor)
def _make_table(self, fields, rows, **atts): table = BaseElement('table', **atts) self._add_table_header(table, fields) for row in rows: self._add_table_row(table, fields, row) return table