added some function for choose date

This commit is contained in:
2026-06-06 09:05:26 +02:00
parent 75e51dacdc
commit fa6f041f12
4 changed files with 215 additions and 5 deletions
+36 -1
View File
@@ -107,9 +107,40 @@ def list_projects():
return projects
@app.post("/preview-time")
async def preview_time_from_csv(file: UploadFile = File(...)):
"""
Parse a file and return the extracted work time without submitting.
"""
content = await file.read()
filename = (file.filename or "").lower()
content_type = (file.content_type or "").lower()
try:
if filename.endswith(".xlsx") or "spreadsheetml" in content_type:
rows = parse_xlsx(content)
else:
rows = parse_csv(content.decode('utf-8-sig'))
except ValueError as e:
raise HTTPException(status_code=400, detail=str(e))
except Exception as e:
raise HTTPException(status_code=400, detail=f"Failed to parse file: {str(e)}")
work_time = extract_work_time(rows)
if not work_time:
raise HTTPException(
status_code=400,
detail="No valid work time found in the uploaded file."
)
return [{"date": k, "hours": v} for k, v in sorted(work_time.items())]
@app.post("/report-time", response_model=TimeReportResponse)
async def report_time_from_csv(
project_name: str,
excluded_dates: str = "",
file: UploadFile = File(...)
):
"""
@@ -168,10 +199,14 @@ async def report_time_from_csv(
work_time = extract_work_time(rows)
if excluded_dates:
excluded_list = [d.strip() for d in excluded_dates.split(",")]
work_time = {k: v for k, v in work_time.items() if k not in excluded_list}
if not work_time:
raise HTTPException(
status_code=400,
detail="No valid work time found in the uploaded CSV."
detail="No valid work time found in the uploaded CSV after filtering."
)
# Submit events