docx_plus.protection.document¶
Document-level protection — the thing that turns a document-with-SDTs
into an actual fillable form. mode="forms" locks every range outside
of a content control; "readOnly" / "comments" / "trackedChanges"
cover the other Word edit-restriction modes.
Unpassworded (SPEC §1 non-goal). Password-protected forms (legacy hash algorithm) remain deferred — neither v0.1 nor the v0.2 cycle added them.
w:documentProtection placement follows CT_Settings schema order
(before w:defaultTabStop) — see ARCHITECTURE.md §7.
docx_plus.protection.document ¶
Document-level protection — the thing that enforces form-fill mode.
Adding content controls makes a document fillable, but it does not stop a
reader from editing surrounding paragraphs. w:documentProtection in
settings.xml flips that switch: with mode="forms" Word locks every
range outside of an SDT, so the only thing the reader can edit is the
content-control fields.
v0.1 protection is unpassworded: it prevents accidental editing, not a determined user. Password-protected forms (legacy hash algorithm; SPEC §1 non-goal) are deferred to v0.2.
This module imports only from docx_plus.core (SPEC §9.1).
ProtectionMode
module-attribute
¶
protect_document ¶
Enforce document protection.
Writes (or replaces) <w:documentProtection w:edit="MODE"
w:enforcement="1"/> in settings.xml. Idempotent: a second call with
a different mode replaces the previous protection rather than
stacking.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc
|
Document
|
The python-docx :class: |
required |
mode
|
ProtectionMode
|
What kind of editing to enforce.
|
'forms'
|
Example
from docx import Document from docx_plus.protection import protect_document doc = Document() protect_document(doc, mode="forms")
Source code in docx_plus/protection/document.py
unprotect_document ¶
Remove any document protection.
Idempotent: a no-op if the document is already unprotected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc
|
Document
|
The python-docx :class: |
required |
Source code in docx_plus/protection/document.py
is_protected ¶
Return True if any protection is currently enforced.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc
|
Document
|
The python-docx :class: |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
bool
|
|
bool
|
read the element's |