• Stars
    star
    101
  • Rank 338,166 (Top 7 %)
  • Language
    Python
  • Created over 11 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

PDF utils

django-pdfutils

A simple django app to generate PDF documents.

Installation

  1. In your settings.py, add pdfutils to your INSTALLED_APPS.
  2. (r'^reports/', include(pdfutils.site.urls)), to your urls.py
  3. Add pdfutils.autodiscover() to your urls.py
  4. Create a report.py file in any installed django application.
  5. Create your report(s)
  6. Profit!

Note: If you are using buildout, don't forget to put pdfutils in your eggs section or else the django-pdfutils dependencies wont be installed.

Example report

Reports are basically views with custom methods and properties.

# -*- coding: utf-8 -*-

from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext as _

from pdfutils.reports import Report
from pdfutils.sites import site


class MyUserReport(Report):
    title = _('Users')
    template_name = 'myapp/reports/users-report.html'
    slug = 'users-report'
    orientation = 'portrait'

    def get_users(self):
        return User.objects.filter(is_staff=True)

    def get_styles(self):
        """
        It is possible to add or override style like so
        """
        self.add_styles('myapp/css/users-report.css')
        return super(AccountStatementReport, self).get_styles()

    def filename(self):
        """
        The filename can be generated dynamically and translated
        """
        return _('Users-report-%(count)s.pdf') % {'count': self.get_users().count() }

    def get_context_data(self):
        """
        Context data is injected just like a normal view
        """
        context = super(AccountStatementReport, self).get_context_data()
        context['user_list'] = self.get_users()
        return context

site.register(MyUserReport)

The slug should obviously be unique since it is used to build the report URL.

For example, with the default settings and URLs, the URL for report above would be /reports/users-report/.

Example template

<html>
    <head>
        {{ STYLES|safe }}
    </head>
    <body class="{% if landscape %}landscape{% else %}portrait{% endif %}">
        <ul>
            {% for user in user_list %}
            <li>{{ user }}</li>
            {% endfor %}
        </ul>
        <a href="{% url 'pdfutils:your_report_slug' %}?format=html">Add ?format=html for easy template debug</a>
    </body>
</html>

Some template variables are injected by default in reports:

  • title
  • slug
  • orientation
  • MEDIA_URL
  • STATIC_URL
  • STYLES

Overriding default CSS

Since the default CSS (base.css, portrait.css, landscape.css) are normal static files, they can be overrided from any other django app which has a pdfutils folder in their static folder.

Note: Be sure your applications are listed in the right order in INSTALLED_APPS !

Dependencies

  • django >=1.4, < 1.5.99
  • decorator == 3.4.0, <= 3.9.9
  • PIL == 1.1.7
  • reportlab == 2.5
  • html5lib == 0.90
  • httplib2 == 0.9
  • pyPdf == 1.13
  • xhtml2pdf == 0.0.4
  • django-xhtml2pdf == 0.0.3

Note: dependencies versions are specified in setup.py. The amount of time required to find the right combination of dependency versions is largely to blame for the creation of this project.

More Repositories

1

django-editlive

Live object editing for django with jQuery UI and Bootsrap
CSS
103
star
2

python-libvin

A fork/rewrite of vinlib: http://pypi.python.org/pypi/vinlib/ (https://github.com/lszyba1/vinlib)
Python
51
star
3

django-courier

Dead simple email notification system
Python
20
star
4

grappelli-fit

A Grappelli compatibility layer for popular Django apps
JavaScript
17
star
5

spec

Bash implementation of color spectrum for IP subneting
Shell
13
star
6

django-colorfield

Simple colorfield for django (optimized for grappelli)
JavaScript
12
star
7

python-dad

Python-dad which stands for Django Automated Deployment is a lightweight Python package which harness the power of virtualenv, pip and fabric to fully automate the development setup and deployment of django projects.
Python
11
star
8

django-seoutils

SEO utils
Python
10
star
9

django-duke-client

test client
Python
6
star
10

django-frontadmin

A django frontadmin ..
JavaScript
6
star
11

SCSS3

CSS3 boilerplate for SASS
6
star
12

django-webcore

Everything needed to build modern websites with Django
JavaScript
6
star
13

django-newsly

Simple drop-in news app for django
Python
5
star
14

django-company

A reusable django application for holding company website infos
Python
5
star
15

django-gallery

Simple gallery system for django
Python
4
star
16

django-slider

A django application to create and manage an image slider
Python
4
star
17

letsencrypt-namecheap-hook

Python
4
star
18

django-checkin

JavaScript
3
star
19

python-kolors

Simple and lightweight shell color output function.
Shell
3
star
20

django-hyperadmin-angularclient

Hyperadmin client written using angular.js
JavaScript
2
star
21

django-bootstrap-ui

Extra form fields for bootstrap
HTML
2
star
22

jquery.shadowdom.js

Experiment trying to emulate the encapsulation of the shadow DOM
JavaScript
2
star
23

django-idefix

JavaScript
2
star
24

django-nav

Quick simple navigation groupings (fork)
Python
2
star
25

bootstrapit

Bootstrap skin generator
JavaScript
2
star
26

django-qooxdoo

my little attempt to make qooxdoo play nice with Django
2
star
27

django-cablegate

Wikileaks cablegate viewer written in Django
JavaScript
2
star
28

python-dploy

Deployment utilities for fabric
Python
2
star
29

django-singularity

Web application framework that mixes Twitter Bootstrap & AngularJS
Python
1
star
30

django-duke-master

test
Python
1
star
31

python-tzu

To come .. maybe.
1
star
32

django-dploy-old

django-dploy (old)
Python
1
star
33

django-moris

Django-moris stands for latin mobilis oris which can be translated as "mobile sight"
JavaScript
1
star
34

django-duke

Test project
Python
1
star
35

django-project-template

My reusable django project template
Python
1
star
36

duke.deploy

A recipe for duke to deploy django projects
Python
1
star
37

django-affiliate

A simple application to manage affiliates
1
star
38

django-unsocial

Middleware to remove social site widgets while developing
Python
1
star
39

django-sitewidgets

Reusable site widgets
Python
1
star
40

grappelli-easythumbnails

Easy thumbnail integration / extension for grappelli
Python
1
star
41

duke-website

Duke test website
Python
1
star
42

string.format.js

JavaScript Advanced String Formatting Γ  la Python
JavaScript
1
star
43

django-awa

Django Apps Widget API (experimental)
1
star
44

siteconfs

Something that is most likely useful only to me
JavaScript
1
star
45

django-grappelli3

Test project with grappelli 2.4 using bootstrap as UI
JavaScript
1
star
46

python-vinapi

python-vinapi
Python
1
star
47

django-inplaceeditform

Django Edit inlive frontend
JavaScript
1
star