Django-Bureaucracy is a small wrapper around the [bureacracy](https://bitbucket.org/maykinmedia/bureaucracy)
package that can be used to generate word and pdf documents from .docx-templates
using Mailmerge fields.
## Installation:
```
pip install --process-dependency-links -e git+https://bitbucket.org/maykinmedia/django-bureaucracy.git#egg=django_bureaucracy-0.1
```
(Note that setuptools is annoying and that this doesn't work without the
`--process-dependency-links` flag which is deprecated. Have fun figuring out
how to do this when it's removed.)
... and then add `django_bureaucracy` to `INSTALLED_APPS`.
## Usage
### Example
```python
from django_bureaucracy.models import Document
# The document model is used to store a template and render documents from a context:
doc = Document(
template_file=File(open('sample.docx')),
type='tps_report',
validate_fields=True,
)
doc.save()
context = {
'table': Table(data=[['this is the first cell of the first row', 'this is the second cell of the first row'],
['the second row', 'etc'],
['etc', 'etc']],
headers=['header 1', 'header 2']),
'image': Image('pigeon.jpg')
'html': HTML("<h1>This is a header from html. And the styling works! Right?</h1><p><strong>bold</strong>-notbold</p><ul><li>hop</li><li>la</li><li>kee</li></ul>")
'text': 'some text',
}
# return bytes of the document generated from the template file and the context
doc_bytes = doc.render(context)
# idem but for pdf bytes:
pdf_bytes = doc.render(context, format='pdf')
# save to a file:
doc.render_to_file(context, '/path/to/file') # docx
doc.render_to_file(context, '/path/to/file', format='pdf') # pdf
```
### Rendering to HTTPResponse with the correct mimetype.
```python
from django_bureaucracy.shortcuts import render_to_download
def view(request)
# (...)
resp = render_to_download(Document.objects.get(...), context, format='docx')
# or...
resp = render_to_download(DocxTemplate(...), context, format='pdf')
# or ...
resp = render_to_download(DocxTemplate('/path/to/file', context)
# or ...
resp = render_to_download(DocxTemplate(file_like_object, context)
return resp
```
### Admin Integration
When the package is installed, `Document`-objects can be created in the
admin. When the `validate_fields` box is checked, the model's `clean` method
will check the `DOCX_TEMPLATE_VARS` setting to see whether the fields in
the template file and the document type match the ones provided in the setting and
raise a `ValidationError` if this is not the case.
```python
# in settings.py
DOCX_TEMPLATE_VARS = {
'tps_report': ['image', 'table', 'html', 'text'],
'letter': ['graph']
}
```
Metadata
Release files for django-bureaucracy 0.4.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-bureaucracy-0.4.2.tar.gz | 7.6 kB | Without provenance | Details for django-bureaucracy-0.4.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_bureaucracy-0.4.2-py3-none-any.whl | Python 3 | none | any | Details for django_bureaucracy-0.4.2-py3-none-any.whl |
Total release size: 18.8 kB
Release files / django-bureaucracy-0.4.2.tar.gz
| Download URL | django-bureaucracy-0.4.2.tar.gz |
|---|---|
| Size | 7.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d508e71d7821acb1b162291f24f1c3f9aac73b7af060d00f33159c7e1f979766
|
|
BLAKE2b-256 checksum How to use checksums |
4f528691c2834a734150fa928fd87c64fe7d498b419ad7f86c41b69c4a8bb837
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / django_bureaucracy-0.4.2-py3-none-any.whl
| Download URL | django_bureaucracy-0.4.2-py3-none-any.whl |
|---|---|
| Size | 11.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
37b194b3c11c2a519f28401a5ce5fe12e3f612aea94655d635f3fdb2d3527ac0
|
|
BLAKE2b-256 checksum How to use checksums |
0f13564b74c7f7437d1df316f4f94b28654a2d5589496eba7668446817c04654
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-bureaucracy 0.4.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.