Add exports panel: versioned drafts, download, upload revisions, mark final
Export DOCX now saves to data/exports/{case_number}/ with auto-versioning
(טיוטה-v1, v2...). The case view UI shows all drafts with download buttons,
allows uploading revised versions (עריכה-v1...), and marking a version as
final (copies to training corpus for style learning).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -53,6 +53,7 @@ ANTHROPIC_API_KEY = os.environ.get("ANTHROPIC_API_KEY", "")
|
||||
# Data directory
|
||||
DATA_DIR = Path(os.environ.get("DATA_DIR", str(Path.home() / "legal-ai" / "data")))
|
||||
TRAINING_DIR = DATA_DIR / "training"
|
||||
EXPORTS_DIR = DATA_DIR / "exports"
|
||||
|
||||
# Cases directory — new structure: cases/{new,in-progress,completed}/{case_number}/
|
||||
CASES_BASE = Path(os.environ.get("CASES_BASE", str(Path.home() / "legal-ai" / "cases")))
|
||||
|
||||
@@ -169,11 +169,20 @@ async def export_decision(case_id: UUID, output_path: str | None = None) -> str:
|
||||
|
||||
_write_block_to_docx(doc, block_id, block["title"], content)
|
||||
|
||||
# Determine output path
|
||||
# Determine output path — versioned under data/exports/{case_number}/
|
||||
if not output_path:
|
||||
case_dir = config.find_case_dir(case["case_number"]) / "output"
|
||||
case_dir.mkdir(parents=True, exist_ok=True)
|
||||
output_path = str(case_dir / f"החלטה-{case['case_number']}.docx")
|
||||
export_dir = config.EXPORTS_DIR / case["case_number"]
|
||||
export_dir.mkdir(parents=True, exist_ok=True)
|
||||
# Find next version number
|
||||
existing = sorted(export_dir.glob("טיוטה-v*.docx"))
|
||||
next_ver = 1
|
||||
for p in existing:
|
||||
try:
|
||||
ver = int(p.stem.split("-v")[1])
|
||||
next_ver = max(next_ver, ver + 1)
|
||||
except (IndexError, ValueError):
|
||||
pass
|
||||
output_path = str(export_dir / f"טיוטה-v{next_ver}.docx")
|
||||
|
||||
Path(output_path).parent.mkdir(parents=True, exist_ok=True)
|
||||
doc.save(output_path)
|
||||
|
||||
Reference in New Issue
Block a user