Skip to content

Commit

Permalink
reformat files
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduard0803 committed Nov 25, 2023
1 parent d12dd6d commit 5d29253
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
16 changes: 11 additions & 5 deletions gestao/web/api/document/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ def generate_affiliation_file(user: User):
docx_replace(
doc,
**{
"cpf": user.cpf[:3] + '.' + user.cpf[3:6] + '.' + user.cpf[6:9] + '-' + user.cpf[9:],
"cpf": user.cpf[:3]
+ "."
+ user.cpf[3:6]
+ "."
+ user.cpf[6:9]
+ "-"
+ user.cpf[9:],
"name": user.name,
"date": date_string,
},
Expand All @@ -48,16 +54,16 @@ def convert_file(file_stream):

docx_name = "tmp_file.docx"
pdf_name = "tmp_file.pdf"

with open(docx_name, "wb") as tmp_file:
tmp_file.write(file_stream.getvalue())

subprocess.call(["libreoffice", "--headless", "--convert-to", "pdf", docx_name])

with open(pdf_name, "rb") as file_out:
file_content = file_out.read()

os.remove(docx_name)
os.remove(pdf_name)

return io.BytesIO(file_content)
4 changes: 1 addition & 3 deletions gestao/web/api/document/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ async def get_user_affiliation(user_id: str) -> None:
pdf_file_stream = convert_file(file_stream)
return StreamingResponse(
pdf_file_stream,
media_type=(
"application/pdf"
),
media_type=("application/pdf"),
)
except Exception:
logging.error("Error occurred while get user", exc_info=True)
Expand Down

0 comments on commit 5d29253

Please sign in to comment.