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.11.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.11.0
File Size Uploaded Provenance
iil_doc_templates-0.11.0.tar.gz 87.1 kB With provenance Details

Built distribution (wheel)

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

Total release size: 163.2 kB

Release files / iil_doc_templates-0.11.0.tar.gz

Download URL iil_doc_templates-0.11.0.tar.gz
Size 87.1 kB
Tags Source
SHA-256 checksum
How to use checksums
ec55a41f148c84aff1cf6639c1b9fe233b8a730172a33ca0129a2235c4264691
BLAKE2b-256 checksum
How to use checksums
e070aeebf4fe7369a1d6a96674a2b638a6c4a2e54e989f90b75e33655fcdd231
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 16, 2026.

Transparency log

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

Download URL iil_doc_templates-0.11.0-py3-none-any.whl
Size 76.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fa5791578df756cce15fb0a488dbe949b7337d9046dd6b882e9e95da8f550a3e
BLAKE2b-256 checksum
How to use checksums
d331b0bec48a6105320d3681440aad3d04307a6e2b1559342a94b335ae561be7
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 16, 2026.

Transparency log

Security for iil-doc-templates 0.11.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.11.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 16, 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