Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def fill_pdf_for_application(application_id):
"""Returns a Filled PDF for the given application_id
Raises an error if no fillable pdf exists or or if it has no file loaded.
"""
app = models.Application.objects.get(id=application_id)
fillable_pdf = models.FillablePDF.objects.filter(
organization_id=app.organization_id).first()
if not fillable_pdf or not fillable_pdf.pdf:
raise exceptions.MissingFillablePDFError(
"{org_name} lacks a pdf to fill for {app}".format(
org_name=app.organization.name, app=app))
return models.FilledPDF.create_with_pdf_bytes(
pdf_bytes=fillable_pdf.fill(app.form_submission),
original_pdf=fillable_pdf,
submission=app.form_submission)
def should_have_a_pdf(self):
"""Returns `True` if `self.organization` has any `FillablePDF`
"""
return bool(
intake.models.FillablePDF.objects.filter(
organization__bundles=self).count())
def fill_pdfs_for_submission(submission, organizations=None):
"""Checks for and creates any needed `FilledPDF` objects
"""
if organizations:
fillables = models.FillablePDF.objects.filter(
organization_id__in=[org.id for org in organizations])
else:
fillables = models.FillablePDF.objects.filter(
organization__submissions=submission)
for fillable in fillables:
fillable.fill_for_submission(submission)
def rebuild_pdf_bundle_for_removed_application(application_id):
app_is_for_org_with_fillable = models.FillablePDF.objects.filter(
organization__applications__id=application_id).exists()
if app_is_for_org_with_fillable:
update_pdf_bundle_for_san_francisco()
def fill_pdfs(self):
"""Checks for and creates any needed `FilledPDF` objects
"""
fillables = FillablePDF.objects.filter(organization__submissions=self)
for fillable in fillables:
fillable.fill_for_submission(self)
def fill_pdfs_for_submission(submission, organizations=None):
"""Checks for and creates any needed `FilledPDF` objects
"""
if organizations:
fillables = models.FillablePDF.objects.filter(
organization_id__in=[org.id for org in organizations])
else:
fillables = models.FillablePDF.objects.filter(
organization__submissions=submission)
for fillable in fillables:
fillable.fill_for_submission(submission)
def should_have_a_pdf(self):
"""Returns `True` if `self.organization` has any `FillablePDF`
"""
return bool(
FillablePDF.objects.filter(organization__bundles=self).count())