Skip to main content

No project description provided

Project description

python-odt-template

PyPI - Version PyPI - Python Version


[!IMPORTANT] This package currently contains minimal features and is a work-in-progress

Table of Contents

Installation

pip install python-odt-template

Usage

Jinja2

from python_odt_template import ODTTemplate
from python_odt_template.jinja import enable_markdown
from python_odt_template.jinja import get_odt_renderer
from python_odt_template.libreoffice import convert_to_pdf

odt_renderer = get_odt_renderer(media_path="inputs")

with ODTTemplate("inputs/simple_template.odt") as template, enable_markdown(template.markdown_filter):
    odt_renderer.render(
        template,
        context={"document": document, "countries": countries},
    )
    template.pack("simple_template_rendered.odt")
    convert_to_pdf("simple_template_rendered.odt", "outputs")

Django

# settings.py

# Add at least one staticfiles dirs, this is what the imgae filter will use to find images
STATICFILES_DIRS = [BASE_DIR / "example" / "static"]

# Add the image filter to the builtins templates config
TEMPLATES = [
    {
        "BACKEND": "django.template.backends.django.DjangoTemplates",
        ...
        "OPTIONS": {
           ...
            "builtins": ["python_odt_template.django"],
        },
    },
]


# views.py
from python_odt_template import ODTTemplate
from python_odt_template.django import get_odt_renderer
from python_odt_template.libreoffice import convert_to_pdf


odt_renderer = get_odt_renderer()


def render_odt(request):
    with ODTTemplate("template.odt") as template:
        odt_renderer.render(
            template,
            {"image": "writer.png"},
        )
        template.pack("template_rendered.odt")
        convert_to_pdf("template_rendered.odt", "outputs")
    return FileResponse(
        open("template_rendered.pdf", "rb"), as_attachment=True, filename="template_rendered.pdf"
    )

Alternatives

Credits

Thanks to secretary for the enormous amount of integration work on Jinja2 and ODT.

License

python-odt-template is distributed under the terms of the MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_odt_template-0.2.0.tar.gz (282.9 kB view details)

Uploaded Source

Built Distribution

python_odt_template-0.2.0-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file python_odt_template-0.2.0.tar.gz.

File metadata

  • Download URL: python_odt_template-0.2.0.tar.gz
  • Upload date:
  • Size: 282.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.26.0

File hashes

Hashes for python_odt_template-0.2.0.tar.gz
Algorithm Hash digest
SHA256 8bb591e97ae6cccf0600a57b3944fdb8d26a1ac365f1f76f014a2414f08b66e4
MD5 d2820c3463780005f2a0d2a50e6b0a9c
BLAKE2b-256 e4eeb8b8c0d462afaa7e7434bb5541266942148303226e0228038a6077ab702d

See more details on using hashes here.

File details

Details for the file python_odt_template-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for python_odt_template-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0c83020fd301b4902f64a5be5128d6c6f27391f8b9271a62da48f51465ffe22d
MD5 6ca36bcd2ff0c6beb266142940c1f335
BLAKE2b-256 6139b59a36d88cf49aa76a0e92b22feb924b00fde476f48fa88436d606931030

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page