Ejemplo n.º 1
0
    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))

        filter_len = filter(lambda col: col is None, tdata.colw)
        try:
            filter_len = len(filter_len)
        except Exception:
            filter_len = sum(1 for _ in filter_len)
        cols_with_no_width = filter_len
        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, _ 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
Ejemplo n.º 2
0
    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 = [tup for tup in enumerate(tdata.colw) if tup[1] is None or tup[1] == 0.0]

        if cols_with_no_width:  # any col width not defined
            log.debug(list(enumerate(tdata.colw)))
            fair_division = str(100 / float(len(cols_with_no_width))) + '%'
            log.debug("Fair division: {}".format(fair_division))
            for i, _ in cols_with_no_width:
                log.debug("Setting {} to {}".format(i, fair_division))
                tdata.colw[i] = fair_division

        log.debug("Col widths: {}".format(list(tdata.colw)))
        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"))

        # Cleanup and re-swap table data
        c.clearFrag()
        c.tableData, self.tableData = self.tableData, None
Ejemplo n.º 3
0
    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))

        filter_len = filter(lambda col: col is None, tdata.colw)
        try:
            filter_len = len(filter_len)
        except Exception:
            filter_len = sum(1 for _ in filter_len)
        cols_with_no_width = filter_len
        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, _ 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.add_story(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.clear_fragment()
        c.tableData, self.tableData = self.tableData, None
Ejemplo n.º 4
0
    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 = [
            tup for tup in enumerate(tdata.colw)
            if tup[1] is None or tup[1] == 0.0
        ]

        if cols_with_no_width:  # any col width not defined
            log.debug(list(enumerate(tdata.colw)))
            fair_division = str(100 / float(len(cols_with_no_width))) + '%'
            log.debug("Fair division: {}".format(fair_division))
            for i, _ in cols_with_no_width:
                log.debug("Setting {} to {}".format(i, fair_division))
                tdata.colw[i] = fair_division

        log.debug("Col widths: {}".format(list(tdata.colw)))
        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"))

        # Cleanup and re-swap table data
        c.clearFrag()
        c.tableData, self.tableData = self.tableData, None