Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Remove os.path calls

Tomasz Szymanski4a7a710963c4
diff --git a/saleor/order/utils.py b/saleor/order/utils.py
index 9014f99db9..128ff4608a 100644
--- a/saleor/order/utils.py
+++ b/saleor/order/utils.py
@@ -1,6 +1,5 @@
-import os.path
from functools import wraps
-from secrets import token_urlsafe
+from uuid import uuid4
from django.conf import settings
from django.contrib.staticfiles import finders as static_finders
@@ -345,16 +344,11 @@ def match_orders_with_new_user(user: User) -> None:
Order.objects.confirmed().filter(user_email=user.email, user=None).update(user=user)
-def _get_unique_pdf_file_name():
- while True:
- pdf_path = f"{settings.MEDIA_ROOT}/{token_urlsafe(32)}.pdf"
- if not os.path.isfile(pdf_path):
- return pdf_path
-
-
def generate_invoice_pdf_for_order(invoice):
logo_path = static_finders.find("images/logo-light.svg")
rendered_template = get_template("invoice.html").render(
{"invoice": invoice, "order": invoice.order, "logo_path": f"file://{logo_path}"}
)
- return HTML(string=rendered_template).write_pdf(_get_unique_pdf_file_name())
+ return HTML(string=rendered_template).write_pdf(
+ f"{settings.MEDIA_ROOT}/{uuid4()}.pdf"
+ )