Manages template draft storage and retrieval on the filesystem.
Each draft is stored in a subdirectory named with a UUIDv4 within
the unified data directory. Each draft contains:
- source.docx: The original uploaded document
- draft_config.json: The template configuration
- markup_overlay.json: Document markup annotations
__init__
__init__(drafts_root_dir: Path | None = None) -> None
Initialize the draft manager.
| Parameters: |
-
drafts_root_dir
(Path | None, default:
None
)
–
Root directory for drafts. If None, uses unified data directory.
|
create_draft
create_draft(uploaded_file: FileStorage) -> str
Create a new draft from an uploaded file.
| Parameters: |
-
uploaded_file
(FileStorage)
–
Flask FileStorage object with the uploaded .docx
|
| Returns: |
-
str( str
) –
The generated draft_id (UUIDv4)
|
create_draft_from_template
Create a new draft from an existing template.
| Parameters: |
-
template_provider
(TemplateDataProvider)
–
VIBE TemplateDataProvider instance
-
template_id
(str)
–
ID of the existing template to copy
|
| Returns: |
-
str( str
) –
The generated draft_id (UUIDv4)
|
get_draft_path
get_draft_path(draft_id: str) -> Path
Get the filesystem path for a draft, with security validation.
| Raises: |
-
ValueError
–
If draft_id contains invalid characters or path traversal
|
draft_exists
draft_exists(draft_id: str) -> bool
Check if a draft exists.
| Returns: |
-
bool( bool
) –
True if the draft directory exists
|
read_json
read_json(draft_id: str, filename: str) -> dict[str, Any]
Read a JSON file from a draft directory.
| Parameters: |
-
draft_id
(str)
–
-
filename
(str)
–
Name of the JSON file to read
|
| Raises: |
-
FileNotFoundError
–
If the draft or file doesn't exist
-
ValueError
–
|
write_json
write_json(draft_id: str, filename: str, data: dict[str, Any]) -> None
Write a JSON file to a draft directory.
| Parameters: |
-
draft_id
(str)
–
-
filename
(str)
–
Name of the JSON file to write
-
data
(dict[str, Any])
–
The data to write as JSON
|
| Raises: |
-
FileNotFoundError
–
If the draft doesn't exist
|
get_source_docx_path
get_source_docx_path(draft_id: str) -> Path
Get the path to the source.docx file for a draft.
| Returns: |
-
Path( Path
) –
Path to the source.docx file
|
| Raises: |
-
FileNotFoundError
–
If the draft or source file doesn't exist
|
delete_draft
delete_draft(draft_id: str) -> None
Delete a draft and all its files.
list_drafts
list_drafts() -> list[str]
List all existing draft IDs.