23 lines
693 B
Python
23 lines
693 B
Python
from __future__ import annotations
|
|
import os
|
|
from typing import List
|
|
|
|
|
|
def list_templates(templates_dir: str) -> dict:
|
|
if not os.path.isdir(templates_dir):
|
|
return {"templates": []}
|
|
templates: List[str] = []
|
|
for entry in os.listdir(templates_dir):
|
|
path = os.path.join(templates_dir, entry)
|
|
if os.path.isfile(path) and entry.lower().endswith(".docx"):
|
|
templates.append(entry)
|
|
templates.sort()
|
|
return {"templates": templates}
|
|
|
|
|
|
def open_template_path(templates_dir: str, name: str) -> str:
|
|
path = os.path.join(templates_dir, name)
|
|
if not os.path.isfile(path):
|
|
raise ValueError(f"Template not found: {name}")
|
|
return path
|