Skip to main content

iil-doc-templates

Reusable Django document template system — create, edit, fill templates with PDF extraction and LLM prefill.

Installation

pip install iil-doc-templates

With optional dependencies:

pip install iil-doc-templates[pdf]   # pdfplumber for PDF extraction
pip install iil-doc-templates[llm]   # iil-aifw for LLM prefill
pip install iil-doc-templates[docx]  # python-docx for the .docx template import
pip install iil-doc-templates[all]   # everything

Quick Start

# settings.py
INSTALLED_APPS = [
    ...
    "doc_templates",
]

# urls.py
path("doc-templates/", include("doc_templates.urls")),

Then run migrations:

python manage.py migrate doc_templates

Features

  • DocumentTemplate — Reusable document templates with JSON structure (sections + fields)
  • DocumentInstance — Filled-out documents based on templates
  • PDF Upload — Extract structure from PDF using iil-concept-templates
  • Interactive Editor — Drag & drop sections, CRUD fields, table columns
  • LLM Prefill — AI-powered field completion via iil-aifw
  • PDF Export — Generate PDF from filled documents via concept_templates.document_renderer
  • Multi-Tenant — All queries filter by tenant_id

Architecture

iil-concept-templates (Pure Python)      iil-doc-templates (Django)
├── Pydantic Schemas                     ├── Django Models
├── PDF Structure Extraction     ──►     ├── CRUD Views + URLs
├── Analysis, Prefill, Export            ├── HTML Templates (6)
└── No Django dependency                 ├── Admin Integration
                                         └── Uses concept_templates internally

Field Types

Type Description
textarea Multi-line text (default)
text Single-line text
number Numeric input
date Date picker
boolean Yes/No toggle
table Table with configurable columns

URL Patterns

URL View Description
/ template-list List all templates + instances
/create/ template-create Create empty template
/upload/ template-upload Create template from PDF
/<pk>/edit/ template-edit Interactive template editor
/<pk>/delete/ template-delete Delete template
/<pk>/instance/create/ instance-create Create document from template
/instance/<pk>/edit/ instance-edit Edit document fields
/instance/<pk>/delete/ instance-delete Delete document
/instance/<pk>/prefill/ instance-prefill LLM prefill endpoint
/instance/<pk>/pdf/ instance-pdf PDF export

Vorlagen-Repository (ADR-042)

Das Modul doc_templates.vorlagen ist das Vorlagen-Repository von SchreibAssist nach meiki:ADR-042. Die Vorlagen eines Amtes liegen in der Postgres-Datenbank des Produkts — kein Dateibaum, kein DMS, kein Git-Pfad. Das Paket bringt das Geruest mit und ausdruecklich keine Hausinhalte: der Weg hinein ist der Upload.

Additiv zum Bestand: DocumentTemplate und DocumentInstance bleiben unveraendert.

Die fuenf Tabellen

Modell Haelt Mandant
Fachbereich Einheit eines Hauses als Referenz (schluessel), nicht als Amtstext tenant_id
Vorlage die Identitaet einer Vorlage — unique je tenant_id + Fachbereich + schluessel tenant_id
VorlagenVersion den Inhalt: text mit {{platzhalter}}, felder, bloecke, qr, Herkunft (quelle_sha256) ueber Vorlage
Feldtabelle Seriendruckfeld → Vorlagenfeld, je Haus (Guenzburg PE_ANREDE1, Traunstein ANREDE) tenant_id
VorlagenAudit wer wann was — ein Eintrag je Workflow-Uebergang ueber Vorlage

Alle mandantentragenden Modelle sind fail-closed (platform:ADR-269):

from doc_templates.vorlagen import tenant_context
from doc_templates.vorlagen.models import Vorlage

Vorlage.objects.all()                    # [] — ohne Mandant gibt es nichts
Vorlage.objects.for_tenant(4711)         # der benannte Weg
with tenant_context(4711):
    Vorlage.objects.all()                # gefiltert auf 4711
Vorlage.objects.alle_mandanten(grund="Betriebsstatistik")   # Begruendung Pflicht

Der Pin

vorlage.freigegebene_version(date(2026, 3, 1))

Genau eine Fassung: die spaeteste mit gueltig_ab <= stichtag, deren Gueltigkeit noch laeuft. Ein Entwurf zaehlt nie — auch nicht als einzige Fassung. Eine abgeloeste Fassung zaehlt fuer Stichtage aus ihrer Zeit, damit ein Bescheid von damals erklaerbar bleibt.

Freigabe-Workflow

Entwurf --einreichen--> Review --freigeben--> Freigegeben --(neue Freigabe)--> Abgeloest
   ^                       |
   +----zurueckgeben-------+
from doc_templates.vorlagen.freigabe import einreichen, freigeben, zurueckgeben

einreichen(version, akteur="sb1", begruendung="Upload geprueft")
freigeben(version, akteur="leitung", gueltig_ab=date(2026, 4, 1))

freigeben setzt die bisher freigegebene Fassung auf Abgeloest und traegt ihr gueltig_bis = gueltig_ab ein — sie wird ersetzt, nicht ueberschrieben. Ein ungueltiger Uebergang ist ein ValueError, kein stilles No-op; Begruendung ist Pflicht bei einreichen und zurueckgeben.

Word-Import

from doc_templates.vorlagen.importer import importiere_docx

version = importiere_docx(datei, vorlage, feldtabelle, akteur="sb1")   # Status: Entwurf
version.unbekannte_felder     # Seriendruckfelder ohne Zuordnung — gemeldet, nie verworfen
version.ist_dublette          # True: dieselbe Datei lag schon vor, keine neue Version

Vier Eigenschaften, die ADR-042 Festlegung 2 tragen ("der Import prueft und lehnt ab"):

  1. Beide Word-Bauformen eines Seriendruckfeldes werden gelesen — w:fldSimple mit w:instr und die w:instrText-Folge zwischen w:fldChar-Markierungen. Wer nur eine liest, findet in der Haelfte der Dateien nichts und haelt sie fuer leer.
  2. Unbekanntes wird gemeldet. Ein Feld ohne Eintrag in der Feldtabelle steht in unbekannte_felder und bleibt im Text als «NAME» sichtbar unaufgeloest. Die Freigabe lehnt eine solche Fassung ab; der Ausweg unvollstaendig_zulassen=True braucht eine Begruendung und steht im Audit.
  3. Die Vorbelegung wird nicht uebernommen. Word haelt in einem Feld die Anweisung und das zuletzt angezeigte Ergebnis; das Ergebnis stammt aus dem letzten Seriendruck und kann personenbezogen sein.
  4. Derselbe Upload zweimal erzeugt keine zweite Version — die Identitaet der Datei ist ihr SHA-256, nicht ihr Dateiname.

Tabellen werden zu bloecke ({typ, pos, zeilen}), Bildinhalte ignoriert. Die Aufloesung ueber die Feldtabelle ist case-insensitiv: dieselbe Vorlage schreibt denselben Namen mal WG_ADAT, mal wg_adat.

Dependencies

  • Required: Django ≥ 5.0, iil-concept-templates ≥ 0.4.0
  • Optional: pdfplumber (PDF extraction), iil-aifw (LLM prefill), python-docx (.docx template import)

Metadata

Release files for iil-doc-templates 0.10.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for iil-doc-templates 0.10.0
File Size Uploaded Provenance
iil_doc_templates-0.10.0.tar.gz 82.9 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for iil-doc-templates 0.10.0
File Interpreter ABI Platform
iil_doc_templates-0.10.0-py3-none-any.whl Python 3 none any Details

Total release size: 155.3 kB

Release files / iil_doc_templates-0.10.0.tar.gz

Download URL iil_doc_templates-0.10.0.tar.gz
Size 82.9 kB
Tags Source
SHA-256 checksum
How to use checksums
8819ac674b8bc261a2322086bbdb951c987e217c07fb91358618f5b21d22aae6
BLAKE2b-256 checksum
How to use checksums
19e4aa66f9eaac5c761a419ac8e76691515d75525b6efb382f30be33e17fab59
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 14, 2026.

Transparency log

Release files / iil_doc_templates-0.10.0-py3-none-any.whl

Download URL iil_doc_templates-0.10.0-py3-none-any.whl
Size 72.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0bf54c6b1c699c076e96e0df627dc32a8218833e6e3e6609a10490b822d04591
BLAKE2b-256 checksum
How to use checksums
c6aa5c8d80b961a6b5e2a573164993d9b87aa8c2666cea46b7b2a55992f89019
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 14, 2026.

Transparency log

Security for iil-doc-templates 0.10.0

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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for iil_doc_templates-0.10.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 14, 2026.

Transparency log

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page