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.4.0.tar.gz (284.9 kB view details)

Uploaded Source

Built Distribution

python_odt_template-0.4.0-py3-none-any.whl (15.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for python_odt_template-0.4.0.tar.gz
Algorithm Hash digest
SHA256 85bc4a8e9860c7eb45b0545954d5b85d1f0cc206ae43154903460d530bd9db0e
MD5 02faee86c91dd93c1417426adc375ed5
BLAKE2b-256 699bd467afe508b2c54b220f9144b76cea609442895d5a6769f0e63a7d459bef

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_odt_template-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 60c2f726098f4c6a8318406fd1ec706c5b8a0e520b491dda5fa4687cd4b8962c
MD5 e06536206850d7c75570f17a016f64d9
BLAKE2b-256 df5d08cef8d6b166114ac43283b6b936ea40ec435d39368e1b58acd8b6d6ca58

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