BTC Weasy PDF
View mixin and template filters for PDF creation from the HTML-template.
Detailed documentation is in the “docs” directory.
Quick start
Add “weasy_pdf” to your INSTALLED_APPS setting like this:
INSTALLED_APPS = ( ... 'weasy_pdf', )Help functions: safety_get_attribute(), safety_parse_dict(), format_date() (see utils.py)
Create data-object. When using the safety_get_attribute() function do not forget to join the related tables (prefetch_related, select_related):
class PDFDataObject: def __init__(self, data_obj: MyModel): get = safety_get_attribute self.data_obj = data_obj self.first_name = get(data_obj, 'first_name') ...Prepare PDF template. Use built-in template filters: times, parse_dict:
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> {% load static %} {% load weasy_pdf %} <link rel="stylesheet" href="{% static '/styles/pdf.css' %}"> <title>Title</title> <meta name="description" content="Description"> <meta name="author" content="Author"> </head> <body> <span>{{ data_object.first_name }}</span> ... </body> </html> <!-- Filters usage: {% for i in 8|times %} <td colspan="2"></td> {% endfor %} <td colspan="5">{{ data_object|parse_dict:'0__NAME' }}</td> -->Prepare view:
class PDFView(WeasyPDFViewMixin): template_name = 'pdf.html' file_name = 'my_pdf.pdf' def get_object(self) -> Any: passport = get_object_or_404(Passport, pk=self.kwargs.get('pk')) return PDFDataObject(passport)
Example
Metadata
Release files for btc-weasy-pdf 0.3
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 |
|---|---|---|---|---|
| btc-weasy-pdf-0.3.tar.gz | 692.3 kB | Without provenance | Details for btc-weasy-pdf-0.3.tar.gz |
Release files / btc-weasy-pdf-0.3.tar.gz
| Download URL | btc-weasy-pdf-0.3.tar.gz |
|---|---|
| Size | 692.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c154ba5087ccbde6a1cb93cfbc7179ec6250b8bb9d917332e82f0ac71dc645e8
|
|
BLAKE2b-256 checksum How to use checksums |
f04661f96c9eec5292076a9964042440c25f2f684aa86ed71a11d68ae05d996b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.7.5
|
Security for btc-weasy-pdf 0.3
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.