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:
    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("outputs/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.3.0.tar.gz (282.0 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for python_odt_template-0.3.0.tar.gz
Algorithm Hash digest
SHA256 fd9ecef3d831a0d508afd7ab927647d0fb136ccff46feb608ea9e052bba48895
MD5 0d01f13ef49f516ed859c35a565a561b
BLAKE2b-256 8f45d1a25feede79d545f8a6c483874011bbcd422e040730258c42858cfbb67c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_odt_template-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7f6c90b97ff370a71b369d8babc49e8c719ddfad39569fd7b7f64aa4203755a7
MD5 52ef31ca729a2c57e9579444284f312b
BLAKE2b-256 a5c602afc208ec1477608fa1fadcfa55d8e383d38ce53109997e0d7806b7512e

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