Skip to main content

Path Template

Project description

Path Template

Install

poetry add pathtmpl

Usage

import uuid
from pathlib import PurePath
from datetime import date as Date
from pathtmpl import DocumentContext, CField, get_evaluated_path


path_tmpl = """
{% if document.cf['Effective Date'] %}
    /home/Tax/{{ document.cf['Effective Date'] | datefmt("%Y") }}.pdf
{% else %}
    /home/Tax/{{ document.id }}.pdf
{% endif %}
"""
custom_fields = [
    CField(name="Total", value=245.02),
    CField(name="Effective Date", value=Date(2024, 12, 23)),
]
doc = DocumentContext(
    id=uuid.uuid4(),
    title="coco",
    custom_fields=custom_fields,
)

ev_path = get_evaluated_path(doc, path_template=path_tmpl)
assert ev_path == PurePath("/home/Tax/2024.pdf")

Tests

poetry run pytest

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

pathtmpl-0.1.0.tar.gz (2.4 kB view hashes)

Uploaded Source

Built Distribution

pathtmpl-0.1.0-py3-none-any.whl (3.4 kB view hashes)

Uploaded Python 3

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