Esempio n. 1
0
    def make_pdf(self, data, start_date, end_date, filename, emails):

        width, height = A4
        styles = getSampleStyleSheet()
        styleN = styles["BodyText"]
        styleN.alignment = TA_LEFT
        styleN.fontName = 'Helvetica'
        styleN.textColor = colors.black
        styleBH = styles["Heading3"]
        styleBH.alignment = TA_CENTER
        styleBH.fontName = 'Helvetica'
        styleBH.textColor = colors.darkslategray
        styleTH = styles["Heading1"]
        styleTH.alignment = TA_CENTER
        styleTH.fontName = 'Helvetica'
        styleTH.textColor = colors.darkslateblue
        styleGH = styles["Heading2"]
        styleGH.alignment = TA_CENTER
        styleGH.fontName = 'Helvetica'
        styleGH.textColor = colors.darkslategray
        #styleGH.backColor = colors.lightgrey

        styleNC = styles["BodyText"]
        #styleNC.alignment = TA_CENTER
        styleNC.fontName = 'Helvetica'

        def coord(x, y, unit=1):
            x, y = x * unit, height - y * unit
            return x, y

        def style_row(row_array, style):
            styled_array = []
            for each in row_array:
                styled_array.extend([Paragraph(str(each), style)])
            return styled_array

        c = canvas.Canvas(os.path.join(settings.PDF_REPORTS_DIR, 'gka_sms/') +
                          filename + ".pdf",
                          pagesize=A4)
        #logo
        logo_image = Image("%s/images/akshara_logo.jpg" %
                           settings.STATICFILES_DIRS)
        logo_image.drawOn(c, *coord(14, 3, cm))
        #HR
        hr = HRFlowable(width="80%",
                        thickness=1,
                        lineCap='round',
                        color=colors.lightgrey,
                        spaceBefore=1,
                        spaceAfter=1,
                        hAlign='CENTER',
                        vAlign='BOTTOM',
                        dash=None)
        hr.wrapOn(c, width, height)
        hr.drawOn(c, *coord(1.8, 3.2, cm))
        #Headings
        header = Paragraph('GKA SMS Summary<br/><hr/>', styleTH)
        header.wrapOn(c, width, height)
        header.drawOn(c, *coord(0, 4, cm))
        #Date Range
        date_range = Paragraph(
            "From " + start_date.strftime("%d %b, %Y") + " to " +
            end_date.strftime("%d %b, %Y"), styleBH)
        date_range.wrapOn(c, width, height)
        date_range.drawOn(c, *coord(0, 4.5, cm))
        #Details
        styled_data = [style_row(data[0], styleGH)]
        for row in data[1:4]:
            styled_data.append(style_row(row, styleN))

        table_header = Table(styled_data, colWidths=[7 * cm, 5 * cm, 5 * cm])
        table_header.setStyle(
            TableStyle([
                ('INNERGRID', (0, 0), (-1, -1), 0.25, colors.lightgrey),
                ('BOX', (0, 0), (-1, -1), 0.25, colors.lightgrey),
                ('LINEBELOW', (0, 0), (2, 0), 1.0, colors.darkgrey),
                ('LINEBELOW', (0, 3), (2, 3), 1.0, colors.darkgrey),
            ]))
        table_header.wrapOn(c, width, height)
        table_header.drawOn(c, *coord(1.8, 9, cm))
        #Questions
        styled_data = [
            style_row(['Questions', 'Yes', 'No', 'Yes', 'No'], styleBH)
        ]
        for row in data[4:len(data)]:
            styled_data.append(style_row(row, styleN))

        table = Table(
            styled_data,
            colWidths=[7 * cm, 2.5 * cm, 2.5 * cm, 2.5 * cm, 2.5 * cm])
        table.setStyle(
            TableStyle([
                ('INNERGRID', (0, 0), (-1, -1), 0.25, colors.lightgrey),
                ('BOX', (0, 0), (-1, -1), 0.25, colors.lightgrey),
                #('LINEBELOW', (0,0), (2, 0), 1.0, colors.green),
            ]))
        table.wrapOn(c, width, height)
        table.drawOn(c, *coord(1.8, 17.5, cm))
        #Footer
        #HR
        hr = HRFlowable(width="80%",
                        thickness=1,
                        lineCap='round',
                        color=colors.lightgrey,
                        spaceBefore=1,
                        spaceAfter=1,
                        hAlign='CENTER',
                        vAlign='BOTTOM',
                        dash=None)
        hr.wrapOn(c, width, height)
        hr.drawOn(c, *coord(1.8, 27, cm))
        #Disclaimer
        klp_text = Paragraph(
            "This report has been generated by Karnataka Learning Partnership(www.klp.org.in/gka) for Akshara Foundation.",
            styleN)
        klp_text.wrapOn(c, width, height)
        klp_text.drawOn(c, *coord(1.8, 27.5, cm))

        c.save()
        self.send_email(
            start_date.strftime("%d/%m/%Y") + " to " +
            end_date.strftime("%d/%m/%Y"), filename, emails)
Esempio n. 2
0
    def make_pdf(self, data, start_date, end_date, filename, emails):

        width, height = A4
        styles = getSampleStyleSheet()
        styleN = styles["BodyText"]
        styleN.alignment = TA_LEFT
        styleN.fontName = 'Helvetica'
        styleN.textColor = colors.black
        styleBH = styles["Heading3"]
        styleBH.alignment = TA_CENTER
        styleBH.fontName = 'Helvetica'
        styleBH.textColor = colors.darkslategray
        styleTH = styles["Heading1"]
        styleTH.alignment = TA_CENTER
        styleTH.fontName = 'Helvetica'
        styleTH.textColor = colors.darkslateblue
        styleGH = styles["Heading2"]
        styleGH.alignment = TA_CENTER
        styleGH.fontName = 'Helvetica'
        styleGH.textColor = colors.darkslategray
        #styleGH.backColor = colors.lightgrey

        styleNC = styles["BodyText"]
        #styleNC.alignment = TA_CENTER
        styleNC.fontName = 'Helvetica'
   

        def coord(x, y, unit=1):
            x, y = x * unit, height -  y * unit
            return x, y

        def style_row(row_array, style):
            styled_array = []
            for each in row_array:
                styled_array.extend([Paragraph(str(each),style)])
            return styled_array
       
            
        c = canvas.Canvas(os.path.join(settings.PDF_REPORTS_DIR, 'gka_sms/')+filename+".pdf", pagesize=A4)
        #logo
        logo_image = Image("%s/images/akshara_logo.jpg" % settings.STATICFILES_DIRS) 
        logo_image.drawOn(c, *coord(14, 3, cm))
        #HR
        hr = HRFlowable(width="80%", thickness=1, lineCap='round', color=colors.lightgrey, spaceBefore=1, spaceAfter=1, hAlign='CENTER', vAlign='BOTTOM', dash=None)
        hr.wrapOn(c, width, height)
        hr.drawOn(c, *coord(1.8, 3.2, cm))
        #Headings
        header = Paragraph('GKA SMS Summary<br/><hr/>', styleTH)
        header.wrapOn(c, width, height)
        header.drawOn(c, *coord(0, 4, cm))
        #Date Range
        date_range = Paragraph("From " + start_date.strftime("%d %b, %Y") + " to " + end_date.strftime("%d %b, %Y"), styleBH)
        date_range.wrapOn(c, width, height)
        date_range.drawOn(c, *coord(0, 4.5, cm))
        #Details
        styled_data = [style_row(data[0],styleGH)]
        for row in data[1:4]:
            styled_data.append(style_row(row,styleN))

        table_header = Table(styled_data, colWidths=[7 * cm,
                                       5* cm, 5 * cm])
        table_header.setStyle(TableStyle([
                       ('INNERGRID', (0,0), (-1,-1), 0.25, colors.lightgrey),
                       ('BOX', (0,0), (-1,-1), 0.25, colors.lightgrey),
                       ('LINEBELOW', (0,0), (2, 0), 1.0, colors.darkgrey),
                       ('LINEBELOW', (0,3), (2, 3), 1.0, colors.darkgrey),
                       
                    ]))
        table_header.wrapOn(c, width, height)
        table_header.drawOn(c, *coord(1.8, 9, cm))
        #Questions
        styled_data =[style_row(['Questions','Yes','No','Yes','No'],styleBH)] 
        for row in data[4:len(data)]:
            styled_data.append(style_row(row,styleN))
        
        table = Table(styled_data, colWidths=[7 * cm,
                                       2.5 * cm, 2.5 * cm,
                                       2.5 * cm, 2.5 * cm])
        table.setStyle(TableStyle([
                       ('INNERGRID', (0,0), (-1,-1), 0.25, colors.lightgrey),
                       ('BOX', (0,0), (-1,-1), 0.25, colors.lightgrey),
                       #('LINEBELOW', (0,0), (2, 0), 1.0, colors.green),
                       
                    ]))
        table.wrapOn(c, width, height)
        table.drawOn(c, *coord(1.8, 17.5, cm))
        #Footer
        #HR
        hr = HRFlowable(width="80%", thickness=1, lineCap='round', color=colors.lightgrey, spaceBefore=1, spaceAfter=1, hAlign='CENTER', vAlign='BOTTOM', dash=None)
        hr.wrapOn(c, width, height)
        hr.drawOn(c, *coord(1.8, 27, cm))
        #Disclaimer
        klp_text = Paragraph("This report has been generated by Karnataka Learning Partnership(www.klp.org.in/gka) for Akshara Foundation.",styleN)
        klp_text.wrapOn(c, width, height)
        klp_text.drawOn(c, *coord(1.8, 27.5, cm))
        
        c.save()
        self.send_email(start_date.strftime("%d/%m/%Y") + " to " + end_date.strftime("%d/%m/%Y"),filename, emails)