From ffdffffdbebaf5e54e235f9b892cab0e5bd75d6e Mon Sep 17 00:00:00 2001 From: fthrslntgy Date: Wed, 20 Dec 2023 16:08:55 +0300 Subject: [PATCH] Add timestamp to pdf report filenames --- helpers/render.py | 4 ++-- main.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/helpers/render.py b/helpers/render.py index 0df9bf6..8e9bf29 100644 --- a/helpers/render.py +++ b/helpers/render.py @@ -1,10 +1,10 @@ from docxtpl import DocxTemplate class RenderClass(): - def render(body): + def render(body, filename): template = DocxTemplate("./templates/%s" % body.TemplateID) for idx,item in enumerate(body.Data): item["idx"] = idx body.Data[idx] = item template.render(body) - template.save("./results/%s.docx" % body.TemplateID) + template.save("./results/%s.docx" % filename) diff --git a/main.py b/main.py index bad7334..e2586f8 100644 --- a/main.py +++ b/main.py @@ -13,8 +13,9 @@ @app.post("/pdf",summary="Creates a pdf report.", tags=["Report"]) def CreatePDFReport(body: ReportCreateRequest): + filename = time.time() RenderClass.render(body) - return FileResponse(Converter.docx2pdf(body.TemplateID)) + return FileResponse(Converter.docx2pdf(filename)) @app.post("/csv",summary="Creates a csv report.", tags=["Report"]) def CreatePDFReport(body: ReportCreateRequest):