def _to_xml_elementtree(self, **kwargs): cfg = { 'tbl_element': 'table', 'row_element': 'row', } cfg.update(kwargs) from augustus.external.lxml.etree import Element, SubElement, ElementTree out = Element(cfg['tbl_element']) out.text = out.tail = '\n' values = [export_string(value) for value in self.values()] cols = [] for col in values: if col is None: col = [col] * len(self) cols.append(col) row_element = cfg['row_element'] keys = self.keys() for rownum in range(len(self)): datarow = SubElement(out, row_element) datarow.tail = '\n' for key, col in zip(keys, cols): datacell = SubElement(datarow, key) datacell.text = str(col[rownum]) return ElementTree(out)
def _to_html_elementtree(self, tblattr=None, method=str): if tblattr is None: tblattr = {'border': '1'} from augustus.external.lxml.etree import Element, SubElement, ElementTree out = Element('table', **tblattr) out.text = out.tail = '\n' headings = SubElement(out, 'tr') headings.tail = '\n' for key in self.keys(): heading = SubElement(headings, 'th') heading.text = method(key) values = [export_string(value) for value in self.values()] cols = [] for col in values: if col is None: col = [col] * len(self) cols.append(col) for rownum in range(len(self)): datarow = SubElement(out, 'tr') datarow.tail = '\n' for col in cols: datacell = SubElement(datarow, 'td') datacell.text = method(col[rownum]) return ElementTree(out)