コード例 #1
0
ファイル: test_pdf.py プロジェクト: erudit/eruditorg
 def test_can_use_a_context(self):
     # Setup
     response_1 = HttpResponse(content_type='application/pdf')
     response_2 = HttpResponse(content_type='application/pdf')
     # Run & check
     generate_pdf('pdf.html', file_object=response_1)
     generate_pdf('pdf.html', file_object=response_2, context={'title': 'test'})
     self.assertTrue(response_2.tell() > response_1.tell())
コード例 #2
0
 def test_can_use_a_context(self):
     # Setup
     response_1 = HttpResponse(content_type='application/pdf')
     response_2 = HttpResponse(content_type='application/pdf')
     # Run & check
     generate_pdf('pdf.html', file_object=response_1)
     generate_pdf('pdf.html',
                  file_object=response_2,
                  context={'title': 'test'})
     self.assertTrue(response_2.tell() > response_1.tell())
コード例 #3
0
ファイル: test_pdf.py プロジェクト: erudit/eruditorg
 def test_can_generate_a_pdf_into_a_http_response(self):
     # Setup
     issue = IssueFactory.create(journal=self.journal)
     article = ArticleFactory.create(issue=issue)
     response = HttpResponse(content_type='application/pdf')
     # Run & check
     generate_pdf(
         'public/journal/article_pdf_coverpage.html',
         file_object=response, context={
             'article': article, 'issue': issue, 'journal': issue.journal})
     self.assertTrue(isinstance(response.content, bytes))
     self.assertTrue(response.tell())
コード例 #4
0
 def test_can_generate_a_pdf_into_a_http_response(self):
     # Setup
     issue = IssueFactory.create(journal=self.journal)
     article = ArticleFactory.create(issue=issue)
     response = HttpResponse(content_type='application/pdf')
     # Run & check
     generate_pdf('public/journal/article_pdf_coverpage.html',
                  file_object=response,
                  context={
                      'article': article,
                      'issue': issue,
                      'journal': issue.journal
                  })
     self.assertTrue(isinstance(response.content, bytes))
     self.assertTrue(response.tell())
コード例 #5
0
ファイル: test_pdf.py プロジェクト: erudit/eruditorg
 def test_generates_a_pdf_into_a_bytes_stream_by_default(self):
     # Setup
     issue = IssueFactory.create(journal=self.journal)
     article = ArticleFactory.create(issue=issue)
     # Run & check
     pdf = generate_pdf('public/journal/article_pdf_coverpage.html', context={
         'article': article, 'issue': issue, 'journal': issue.journal})
     self.assertTrue(isinstance(pdf, io.BytesIO))
コード例 #6
0
 def test_generates_a_pdf_into_a_bytes_stream_by_default(self):
     # Setup
     issue = IssueFactory.create(journal=self.journal)
     article = ArticleFactory.create(issue=issue)
     # Run & check
     pdf = generate_pdf('public/journal/article_pdf_coverpage.html',
                        context={
                            'article': article,
                            'issue': issue,
                            'journal': issue.journal
                        })
     self.assertTrue(isinstance(pdf, io.BytesIO))
コード例 #7
0
ファイル: views.py プロジェクト: erudit/eruditorg
    def write_datastream_content(self, response, content):
        # We are going to put a generated coverpage at the beginning of our PDF
        article = self.get_article()
        xml_content = self.fedora_object.xml_content

        coverpage_context = {
            'article': article,
            'issue': article.issue,
            'journal': article.issue.journal,
            'fedora_article': self.fedora_object,
            'erudit_article': EruditArticle(xml_content) if xml_content else None,
        }
        coverpage = generate_pdf(
            'public/journal/article_pdf_coverpage.html',
            context=RequestContext(self.request).update(coverpage_context),
            base_url=self.request.build_absolute_uri('/'))

        # Merges the cover page and the full article
        merger = PdfFileMerger()
        merger.append(coverpage)
        merger.append(content)
        merger.write(response)
        merger.close()