Skip to content

Commit

Permalink
Add timestamp to pdf report filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
fthrslntgy committed Dec 20, 2023
1 parent 3b7ea62 commit ffdffff
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions helpers/render.py
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 2 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit ffdffff

Please sign in to comment.