Esempio n. 1
0
    def go(self):
        """Render the PDF foer individual item."""
        doc = SimpleDocTemplate(self.buf,
                                leftMargin=LEFTMARGIN,
                                rightMargin=RIGHTMARGIN)
        doc.title = self.filename
        doc.creator = "Romain Belia."
        doc.author = "Romain Belia."
        doc.subject = "Report created by Romain Belia."
        doc.keywords = ["report", "Romain Belia"]
        story = []
        # First Page

        story.append(self._build_title("The Report"))
        story.append(Spacer(1, 1 * cm))
        story.append(
            self._build_document_title("organization", self.organization))
        story.append(
            self._build_document_title("reported_at", self.reported_at))
        story.append(self._build_document_title("created_at", self.created_at))
        story.append(Spacer(1, 1 * cm))
        story.append(Spacer(1, 1 * cm))
        if not self.inventory:
            story.append(self._build_no_content())
        for x in self.inventory:
            story.append(self._build_document_content(x))
            story.append(Spacer(1, 1 * cm))
        story.append(PageBreak())

        doc.build(story,
                  onFirstPage=self.firstpage,
                  onLaterPages=self.laterpages)
        return
Esempio n. 2
0
    def go_all(self):
        """Render the PDF for all items."""
        doc = SimpleDocTemplate(self.buf,
                                leftMargin=LEFTMARGIN,
                                rightMargin=RIGHTMARGIN)
        doc.title = self.filename
        doc.creator = "Romain Belia."
        doc.author = "Romain Belia."
        doc.subject = "Report created by Romain Belia."
        doc.keywords = ["report", "Romain Belia"]
        story = []
        # First Page

        story.append(self._build_title("Full Report"))
        story.append(Spacer(1, 1 * cm))
        for item in self.data:
            data = item['data']
            inventory = data['inventory'] if 'inventory' in data else []
            if 'id' in item:
                story.append(self._build_document_title("id", item['id']))
            if 'organization' in data:
                story.append(
                    self._build_document_title("organization",
                                               data['organization']))
            if 'reported_at' in data:
                story.append(
                    self._build_document_title("reported_at",
                                               data['reported_at']))
            if 'created_at' in data:
                story.append(
                    self._build_document_title("created_at",
                                               data['created_at']))
            story.append(Spacer(1, 1 * cm))
            story.append(Spacer(1, 1 * cm))
            if not inventory:
                story.append(self._build_no_content())
            for x in inventory:
                story.append(self._build_document_content(x))
                story.append(Spacer(1, 1 * cm))
            story.append(PageBreak())

        doc.build(story,
                  onFirstPage=self.firstpage,
                  onLaterPages=self.laterpages)
        return