Reference

This document covers various components of django-pdf.

Settings

PDF_UPLOAD_PATH

Path on web server where PDF files are uploaded to at first. Defaults to os.path.join(settings.MEDIA_ROOT, "uploads").

PDF_UPLOAD_PATH = os.path.join(settings.MEDIA_ROOT, "uploads")

PDF_REQUEST_QUEUE

Amazon SQS queue name which will be used to transmit the requests. Defaults to pdf_requests.

PDF_REQUEST_QUEUE = "pdf_requests"

PDF_RESPONSE_QUEUE

Amazon SQS queue name which will be used in the cloud to post response messages after jobs complete. Defaults to pdf_responses.

PDF_RESPONSE_QUEUE = "pdf_responses"

PDF_AWS_ACL

The ACL of the Amazon S3 objects that will be created. Defaults to public-read.

PDF_AWS_ACL = "public-read"

PDF_AMI_ID

The Amazon EC2 Image ID of the machine that will be used to boot up, bootstrap, and then run the script to convert PDFs. This defaults to the Canonical Ubuntu Image.

PDF_AMI_ID = "ami-bb709dd2"

PDF_MAX_NODES

The maximum number of concurrent nodes to boot up on EC2. Defaults to 20.

PDF_MAX_NODES = 150

By default, accounts on EC2 are given a concurrency maximum of 20 nodes. You can request more, but you will get an exception from AWS if you request to boot more nodes that your account is configured to be allowed.

PDF_SECURITY_GROUPS

This is a list of strings which correspond to named and previously configured security groups for EC2 nodes to run under. More specifically, they define firewall rules. Defaults to None since for this application, the nodes don’t need to be access externally.

PDF_SECURITY_GROUPS = ["web", "ftp"]

PDF_KEYPAIR_NAME

The AWS EC2 Keypair name to use in booting your images (in case you want to log into them):

PDF_KEYPAIR_NAME = "my-keypair-name"

PDF_AWS_KEY

Required. AWS Key for accessing Bootstrap Bucket and Queues.

PDF_AWS_KEY = "xxxxxxxx"

PDF_AWS_SECRET

Required. AWS Secret Key for accessing Bootstrap Bucket and Queues.

PDF_AWS_SECRET = "xxxxxxxxxxxx"

PDF_UPLOAD_BUCKET

Required. The Amazon S3 bucket where PDF files will be uploaded to.

PDF_UPLOAD_BUCKET = "my_pdf_bucket"  # must be globally unique

Named URLs

The named URLs in this app should enable the use of of the {% url %} template tag as well as reverse lookups in your project code without having to know the implementation details of this app.

pdf_list

Renders the list.html template with a collection of pdf.models.Document objects in context.

pdf_upload

On GET requests, renders the upload.html template with a pdf.forms.DocumentForm instance in context.

On POST requests, process the form and handle the upload, in addition to kicking off the back ground asynchronous task to process the upload. It then redirects to pdf_list.

pdf_detail

Renders the detail.html template with a single pdf.models.Document instance in context.

keyword arguments:
 The UUID of the document to display. Must match (?P<uuid>[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}).

Templates

Templates should be placed in an pdf/ folder at the root of one of your template search paths.

detail.html

context:pdf

list.html

context:pdfs

upload.html

context:form

Modules

pdf.admin

pdf.forms

class pdf.forms.DocumentField(*args, **kwargs)

A validating PDF document upload field

clean(data, initial=None)
class pdf.forms.DocumentForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.util.ErrorList'>, label_suffix=':', empty_permitted=False, instance=None)
class Meta
model
alias of Document
DocumentForm.media
exception pdf.forms.DocumentValidationError

pdf.models

class pdf.models.Document(*args, **kwargs)

A simple model which stores data about an uploaded document.

exception DoesNotExist
exception Document.MultipleObjectsReturned
Document.get_detail_url()
Document.get_next_by_date_created(*moreargs, **morekwargs)
Document.get_next_by_date_uploaded(*moreargs, **morekwargs)
Document.get_previous_by_date_created(*moreargs, **morekwargs)
Document.get_previous_by_date_uploaded(*moreargs, **morekwargs)
Document.get_status_display(*moreargs, **morekwargs)
Document.page_images
static Document.process_response(data)
Document.save(**kwargs)
Document.user

pdf.tasks

class pdf.tasks.CheckQueueLevelsTask

Checks the number of messages in the queue and compares it with the number of instances running, only booting nodes if the number of queued messages exceed the number of nodes running.

run(**kwargs)
class pdf.tasks.CheckResponseQueueTask

Checks response queue for messages returned from running processes in the cloud. The messages are read and corresponding pdf.models.Document records are updated.

run(**kwargs)
pdf.tasks.queue_json_message(doc, doc_key)
pdf.tasks.upload_file_to_s3(doc)

pdf.views

pdf.views.doc_detail(request, *args, **kwargs)
pdf.views.doc_list(request, *args, **kwargs)
pdf.views.doc_upload(request, *args, **kwargs)