python类A4的实例源码

result_report.py 文件源码 项目:shcft 作者: celiadominguez 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def generateReport(self, results):

        #Pintamos la tabla con sus contenidos
        doc = IOCDocTemplate(DEFAULT_REPORT_NAME, pagesize=A4, results=results)

        doc.addPageTemplates(
            [
                PageTemplate(id='summary',
                             frames=[Frame(doc.leftMargin, doc.bottomMargin, doc.width, 425)],
                             onPage=doc.summary, onPageEnd=doc.footer),

                PageTemplate(id='content',
                             frames=[Frame(doc.leftMargin, doc.bottomMargin, doc.width, doc.height)],
                             onPage=doc.header, onPageEnd=doc.footer),

            ]
        )

        estiloHoja = getSampleStyleSheet()

        # Estilos de la tabla para cabeceras y datos
        thead = estiloHoja["BodyText"]
        thead.fontSize = 7

        table_data = [ ['INDICADOR DE COMPROMISO', 'FORMATO', 'TIPO DE EVIDENCIA', 'VALOR', 'PRUEBA'] ]
        for incident in results.incidents:
            for evidence in incident.evidences:
                table_data.append([Paragraph(self.__prettyPrint__(incident.indicator.id),thead),
                                   Paragraph(self.__prettyPrint__(incident.indicator.format.value),thead),
                                   Paragraph(self.__prettyPrint__(evidence.context),thead),
                                   Paragraph(self.__prettyPrint__(evidence.value),thead),
                                   Paragraph(self.__prettyPrint__(evidence.proof),thead)])

        table_report=[]
        table_report.append(NextPageTemplate('summary'))
        table_report.append(NextPageTemplate('content'))
        table_report.append(Table(table_data, colWidths=[120, 50, 75, 120, 180],
                              style=TableStyle([
                                  ('ALIGN', (0, 0), (-1, 0), 'CENTER'),
                                  ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'),
                                  ('SIZE', (0, 0), (-1, -1), 7),
                                  ('GRID', (0, 0), (-1, -1), 0.5, colors.black),
                                  ('BOX', (0, 0), (-1, -1), 1, colors.black),
                                  ('BACKGROUND', (0, 0), (-1, 0), colors.lavender),
                              ])
                              )
                            )

        doc.build(table_report)


问题


面经


文章

微信
公众号

扫码关注公众号