コード例 #1
0
ファイル: bundles.py プロジェクト: vcgato29/intake
def build_bundled_pdf_if_necessary(bundle):
    """Populates `bundled_pdf` attribute if needed

    First checks whether or not there should be a pdf. If so,
    - tries to grab filled pdfs for the bundles submissions
    - if it needs a pdf but there weren't any pdfs, it logs an error and
      creates the necessary filled pdfs.
    - makes a filename based on the organization and current time.
    - adds the file data and saves itself.
    """
    needs_pdf = bundle.should_have_a_pdf()
    if not needs_pdf:
        return
    submissions = bundle.submissions.all()
    filled_pdfs = bundle.get_individual_filled_pdfs()
    missing_filled_pdfs = (not filled_pdfs
                           or (len(submissions) > len(filled_pdfs)))
    if needs_pdf and missing_filled_pdfs:
        msg = str("Submissions for ApplicationBundle(pk={}) lack pdfs").format(
            bundle.pk)
        logger.error(msg)
        intake.notifications.slack_simple.send(msg)
        for submission in submissions:
            SubmissionsService.fill_pdfs_for_submission(submission)
        filled_pdfs = bundle.get_individual_filled_pdfs()
    if len(filled_pdfs) == 1:
        bundle.set_bundled_pdf_to_bytes(filled_pdfs[0].pdf.read())
    else:
        bundle.set_bundled_pdf_to_bytes(get_parser().join_pdfs(
            filled.pdf for filled in filled_pdfs))
    bundle.save()
コード例 #2
0
def set_bytes_to_filled_pdfs(instance, filled_pdfs):
    if len(filled_pdfs) == 0:
        instance.pdf = None
    elif len(filled_pdfs) == 1:
        instance.set_bytes(filled_pdfs[0].pdf.read())
    else:
        instance.set_bytes(models.get_parser().join_pdfs(
            filled.pdf for filled in filled_pdfs))
    instance.save()
コード例 #3
0
 def test_calls_pdfparser_correctly(self):
     sf_pubdef = auth_models.Organization.objects.get(slug='sf_pubdef')
     fillable = mock.fillable_pdf(organization=sf_pubdef)
     subs = [
         SubmissionsService.create_for_organizations(
             [sf_pubdef],
             answers=mock.fake.cleaned_sf_county_form_answers())
         for i in range(2)]
     pdfs = [fillable.fill_for_submission(sub) for sub in subs]
     parser = models.get_parser()
     result = parser.join_pdfs(filled.pdf for filled in pdfs)
     self.assertTrue(len(result) > 30000)