def end(self, c): tdata = c.tableData data = tdata.get_data() # Add missing columns so that each row has the same count of columns # This prevents errors in Reportlab table try: maxcols = max([len(row) for row in data] or [0]) except ValueError: log.warn(c.warning("<table> rows seem to be inconsistent")) maxcols = [0] for i, row in enumerate(data): data[i] += [''] * (maxcols - len(row)) cols_with_no_width = len(filter(lambda col: col is None, tdata.colw)) if cols_with_no_width: # any col width not defined bad_cols = filter(lambda tup: tup[1] is None, enumerate(tdata.colw)) fair_division = str( 100 / float(cols_with_no_width)) + '%' # get fair % for i, col in bad_cols: tdata.colw[i] = fair_division # fix empty with fair % try: if tdata.data: # log.debug("Table styles %r", tdata.styles) t = PmlTable( data, colWidths=tdata.colw, rowHeights=tdata.rowh, # totalWidth = tdata.width, splitByRow=1, # repeatCols = 1, repeatRows=tdata.repeat, hAlign=tdata.align, vAlign='TOP', style=TableStyle(tdata.styles)) t.totalWidth = _width(tdata.width) t.spaceBefore = c.frag.spaceBefore t.spaceAfter = c.frag.spaceAfter # XXX Maybe we need to copy some more properties? t.keepWithNext = c.frag.keepWithNext # t.hAlign = tdata.align c.addStory(t) else: log.warn(c.warning("<table> is empty")) except: log.warn(c.warning("<table>"), exc_info=1) # Cleanup and re-swap table data c.clearFrag() c.tableData, self.tableData = self.tableData, None
def end(self, c): tdata = c.tableData data = tdata.get_data() # Add missing columns so that each row has the same count of columns # This prevents errors in Reportlab table try: maxcols = max([len(row) for row in data] or [0]) except ValueError: log.warn(c.warning("<table> rows seem to be inconsistent")) maxcols = [0] for i, row in enumerate(data): data[i] += [''] * (maxcols - len(row)) cols_with_no_width = len(filter(lambda col: col is None, tdata.colw)) if cols_with_no_width: # any col width not defined bad_cols = filter(lambda tup: tup[1] is None, enumerate(tdata.colw)) fair_division = str(100/float(cols_with_no_width))+'%' # get fair % for i,col in bad_cols: tdata.colw[i] = fair_division # fix empty with fair % try: if tdata.data: # log.debug("Table styles %r", tdata.styles) t = PmlTable( data, colWidths=tdata.colw, rowHeights=tdata.rowh, # totalWidth = tdata.width, splitByRow=1, # repeatCols = 1, repeatRows=tdata.repeat, hAlign=tdata.align, vAlign='TOP', style=TableStyle(tdata.styles)) t.totalWidth = _width(tdata.width) t.spaceBefore = c.frag.spaceBefore t.spaceAfter = c.frag.spaceAfter # XXX Maybe we need to copy some more properties? t.keepWithNext = c.frag.keepWithNext # t.hAlign = tdata.align c.addStory(t) else: log.warn(c.warning("<table> is empty")) except: log.warn(c.warning("<table>"), exc_info=1) # Cleanup and re-swap table data c.clearFrag() c.tableData, self.tableData = self.tableData, None
def end(self, c): tdata = c.tableData data = tdata.get_data() # Add missing columns so that each row has the same count of columns # This prevents errors in Reportlab table try: maxcols = max([len(row) for row in data] or [0]) except ValueError: log.warn(c.warning("<table> rows seem to be inconsistent")) maxcols = [0] for i, row in enumerate(data): data[i] += [''] * (maxcols - len(row)) try: if tdata.data: # log.debug("Table sryles %r", tdata.styles) t = PmlTable( data, colWidths=tdata.colw, rowHeights=tdata.rowh, # totalWidth = tdata.width, splitByRow=1, # repeatCols = 1, repeatRows=tdata.repeat, hAlign=tdata.align, vAlign='TOP', style=TableStyle(tdata.styles)) t.totalWidth = _width(tdata.width) t.spaceBefore = c.frag.spaceBefore t.spaceAfter = c.frag.spaceAfter # XXX Maybe we need to copy some more properties? t.keepWithNext = c.frag.keepWithNext # t.hAlign = tdata.align c.addStory(t) else: log.warn(c.warning("<table> is empty")) except SoftTimeLimitExceeded: raise except: log.warn(c.warning("<table>"), exc_info=1) # Cleanup and re-swap table data c.clearFrag() c.tableData, self.tableData = self.tableData, None
def end(self, c): tdata = c.tableData data = tdata.get_data() # Add missing columns so that each row has the same count of columns # This prevents errors in Reportlab table maxcols = max([len(row) for row in data] or [0]) for i, row in enumerate(data): data[i] += [''] * (maxcols - len(row)) try: if tdata.data: # log.debug("Table sryles %r", tdata.styles) t = PmlTable( data, colWidths=tdata.colw, rowHeights=tdata.rowh, # totalWidth = tdata.width, splitByRow=1, # repeatCols = 1, repeatRows=tdata.repeat, hAlign=tdata.align, vAlign='TOP', style=TableStyle(tdata.styles)) t.totalWidth = _width(tdata.width) t.spaceBefore = c.frag.spaceBefore t.spaceAfter = c.frag.spaceAfter # XXX Maybe we need to copy some more properties? t.keepWithNext = c.frag.keepWithNext # t.hAlign = tdata.align c.addStory(t) else: log.warn(c.warning("<table> is empty")) except: log.warn(c.warning("<table>"), exc_info=1) # Cleanup and re-swap table data c.clearFrag() c.tableData, self.tableData = self.tableData, None