coming together
This commit is contained in:
@@ -118,10 +118,18 @@ async def create_qdro(
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Create new QDRO"""
|
||||
qdro = QDRO(**qdro_data.model_dump())
|
||||
# Only accept fields that exist on the model and exclude None values
|
||||
allowed_fields = {c.name for c in QDRO.__table__.columns}
|
||||
payload = {
|
||||
k: v
|
||||
for k, v in qdro_data.model_dump(exclude_unset=True).items()
|
||||
if v is not None and k in allowed_fields
|
||||
}
|
||||
qdro = QDRO(**payload)
|
||||
|
||||
if not qdro.created_date:
|
||||
qdro.created_date = date.today()
|
||||
# Backfill created_date if model supports it; otherwise rely on created_at
|
||||
if hasattr(qdro, "created_date") and not getattr(qdro, "created_date"):
|
||||
setattr(qdro, "created_date", date.today())
|
||||
|
||||
db.add(qdro)
|
||||
db.commit()
|
||||
@@ -172,9 +180,11 @@ async def update_qdro(
|
||||
detail="QDRO not found"
|
||||
)
|
||||
|
||||
# Update fields
|
||||
# Update fields present on the model only
|
||||
allowed_fields = {c.name for c in QDRO.__table__.columns}
|
||||
for field, value in qdro_data.model_dump(exclude_unset=True).items():
|
||||
setattr(qdro, field, value)
|
||||
if field in allowed_fields:
|
||||
setattr(qdro, field, value)
|
||||
|
||||
db.commit()
|
||||
db.refresh(qdro)
|
||||
@@ -525,23 +535,33 @@ async def generate_document(
|
||||
document_id = str(uuid.uuid4())
|
||||
file_name = f"{template.form_name}_{file_obj.file_no}_{date.today().isoformat()}"
|
||||
|
||||
exports_dir = "/app/exports"
|
||||
try:
|
||||
os.makedirs(exports_dir, exist_ok=True)
|
||||
except Exception:
|
||||
try:
|
||||
os.makedirs("exports", exist_ok=True)
|
||||
exports_dir = "exports"
|
||||
except Exception:
|
||||
exports_dir = "."
|
||||
|
||||
if request.output_format.upper() == "PDF":
|
||||
file_path = f"/app/exports/{document_id}.pdf"
|
||||
file_path = f"{exports_dir}/{document_id}.pdf"
|
||||
file_name += ".pdf"
|
||||
# Here you would implement PDF generation
|
||||
# For now, create a simple text file
|
||||
with open(f"/app/exports/{document_id}.txt", "w") as f:
|
||||
with open(f"{exports_dir}/{document_id}.txt", "w") as f:
|
||||
f.write(merged_content)
|
||||
file_path = f"/app/exports/{document_id}.txt"
|
||||
file_path = f"{exports_dir}/{document_id}.txt"
|
||||
elif request.output_format.upper() == "DOCX":
|
||||
file_path = f"/app/exports/{document_id}.docx"
|
||||
file_path = f"{exports_dir}/{document_id}.docx"
|
||||
file_name += ".docx"
|
||||
# Implement DOCX generation
|
||||
with open(f"/app/exports/{document_id}.txt", "w") as f:
|
||||
with open(f"{exports_dir}/{document_id}.txt", "w") as f:
|
||||
f.write(merged_content)
|
||||
file_path = f"/app/exports/{document_id}.txt"
|
||||
file_path = f"{exports_dir}/{document_id}.txt"
|
||||
else: # HTML
|
||||
file_path = f"/app/exports/{document_id}.html"
|
||||
file_path = f"{exports_dir}/{document_id}.html"
|
||||
file_name += ".html"
|
||||
html_content = f"<html><body><pre>{merged_content}</pre></body></html>"
|
||||
with open(file_path, "w") as f:
|
||||
@@ -768,6 +788,9 @@ async def upload_document(
|
||||
|
||||
max_size = 10 * 1024 * 1024 # 10MB
|
||||
content = await file.read()
|
||||
# Treat zero-byte payloads as no file uploaded to provide a clearer client error
|
||||
if len(content) == 0:
|
||||
raise HTTPException(status_code=400, detail="No file uploaded")
|
||||
if len(content) > max_size:
|
||||
raise HTTPException(status_code=400, detail="File too large")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user