Przeglądaj źródła

use base dir for file paths

Nikos Atlas 7 miesięcy temu
rodzic
commit
967ee1bb4e

+ 2 - 1
src/telecaster/Clients/CosmohomeClient.py

@@ -5,6 +5,7 @@ from datetime import datetime
 from functools import lru_cache
 
 from dicttoxml import dicttoxml
+from django.conf import settings
 
 from telecaster.Clients.PrestaShopClient import PrestaShopClient
 
@@ -270,5 +271,5 @@ def generate_xml():
 
 def generate_xml_task():
     xml = generate_xml()
-    with open('artifacts/cosmohome_products.xml', 'w') as file:
+    with open(settings.BASE_DIR / 'artifacts/cosmohome_products.xml', 'w') as file:
         file.write(xml)

+ 2 - 1
src/telecaster/views/CosmohomeView.py

@@ -4,6 +4,7 @@ from rest_framework.request import Request
 from django.http import HttpResponse
 
 from ..Clients.CosmohomeClient import generate_xml_task
+from django.conf import settings
 
 
 class CosmohomeView(viewsets.ViewSet):
@@ -16,7 +17,7 @@ class CosmohomeView(viewsets.ViewSet):
     @classmethod
     @action(methods=['get'], detail=False, url_path='xml')
     def xml(cls, request: Request, *args, **kwargs) -> HttpResponse:
-        file = "artifacts/cosmohome_products.xml"
+        file = settings.BASE_DIR / "artifacts/cosmohome_products.xml"
         try:
             with open(file, 'rb') as f:
                 return HttpResponse(f.read(), content_type='text/xml')