fix: path to pdf file
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import io
|
import io
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
|
from django.contrib.staticfiles import finders
|
||||||
from django.core.files import File
|
from django.core.files import File
|
||||||
from pypdf import PdfReader, PdfWriter
|
from pypdf import PdfReader, PdfWriter
|
||||||
|
|
||||||
@@ -46,8 +46,8 @@ def generate_rental_pdf(rental: Rental) -> bool:
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Write data in pdf
|
# Write data in pdf
|
||||||
pdf_path = Path(Path(__file__).parent) / "static/rental/Verleihformular.pdf"
|
pdf_path_str = finders.find("rental/Verleihformular.pdf")
|
||||||
reader = PdfReader(pdf_path)
|
reader = PdfReader(pdf_path_str)
|
||||||
writer = PdfWriter()
|
writer = PdfWriter()
|
||||||
writer.append(reader)
|
writer.append(reader)
|
||||||
|
|
||||||
@@ -58,6 +58,7 @@ def generate_rental_pdf(rental: Rental) -> bool:
|
|||||||
|
|
||||||
with io.BytesIO() as bytes_stream:
|
with io.BytesIO() as bytes_stream:
|
||||||
writer.write(bytes_stream)
|
writer.write(bytes_stream)
|
||||||
|
bytes_stream.seek(0)
|
||||||
|
|
||||||
# Save pdf in rental
|
# Save pdf in rental
|
||||||
rental_name = f"Verleihformular-{str(rental.pk).zfill(4)}.pdf"
|
rental_name = f"Verleihformular-{str(rental.pk).zfill(4)}.pdf"
|
||||||
|
|||||||
Reference in New Issue
Block a user