Skip to content

Commit

Permalink
Return correct filename value
Browse files Browse the repository at this point in the history
  • Loading branch information
fthrslntgy committed Dec 20, 2023
1 parent 1ce64c0 commit 68fb128
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions helpers/docx2pdf.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import os

class Converter():
def docx2pdf(file_name):
docx_file = "./results/%d.docx" % file_name
os.system('soffice --headless --norestore --writer --convert-to pdf ./%s --outdir %s' % (docx_file, "./reports"))
os.remove(docx_file)

return "./reports/%s.pdf" % docx_file
def docx2pdf(timestamp):
template_filename = "./results/%d.docx" % timestamp
os.system('soffice --headless --norestore --writer --convert-to pdf ./%s --outdir %s' % (template_filename, "./reports"))
os.remove(template_filename)
report_filename = "./reports/%d.docx.pdf" % timestamp
return report_filename

def docx2preview(file_name):
os.system('soffice --headless --norestore --writer --convert-to pdf %s --outdir %s' % (file_name, "./templates"))
Expand Down
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, filename):
def render(body, timestamp):
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/%d.docx" % filename)
template.save("./results/%d.docx" % timestamp)
6 changes: 3 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

@app.post("/pdf",summary="Creates a pdf report.", tags=["Report"])
def CreatePDFReport(body: ReportCreateRequest):
filename = time.time()
RenderClass.render(body, filename)
return FileResponse(Converter.docx2pdf(filename))
timestamp = time.time()
RenderClass.render(body, timestamp)
return FileResponse(Converter.docx2pdf(timestamp))

@app.post("/csv",summary="Creates a csv report.", tags=["Report"])
def CreatePDFReport(body: ReportCreateRequest):
Expand Down

0 comments on commit 68fb128

Please sign in to comment.