Browse Source

use base dir for file paths

Nikos Atlas 9 months ago
parent
commit
967ee1bb4e

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

@@ -5,6 +5,7 @@ from datetime import datetime
 from functools import lru_cache
 from functools import lru_cache
 
 
 from dicttoxml import dicttoxml
 from dicttoxml import dicttoxml
+from django.conf import settings
 
 
 from telecaster.Clients.PrestaShopClient import PrestaShopClient
 from telecaster.Clients.PrestaShopClient import PrestaShopClient
 
 
@@ -270,5 +271,5 @@ def generate_xml():
 
 
 def generate_xml_task():
 def generate_xml_task():
     xml = generate_xml()
     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)
         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 django.http import HttpResponse
 
 
 from ..Clients.CosmohomeClient import generate_xml_task
 from ..Clients.CosmohomeClient import generate_xml_task
+from django.conf import settings
 
 
 
 
 class CosmohomeView(viewsets.ViewSet):
 class CosmohomeView(viewsets.ViewSet):
@@ -16,7 +17,7 @@ class CosmohomeView(viewsets.ViewSet):
     @classmethod
     @classmethod
     @action(methods=['get'], detail=False, url_path='xml')
     @action(methods=['get'], detail=False, url_path='xml')
     def xml(cls, request: Request, *args, **kwargs) -> HttpResponse:
     def xml(cls, request: Request, *args, **kwargs) -> HttpResponse:
-        file = "artifacts/cosmohome_products.xml"
+        file = settings.BASE_DIR / "artifacts/cosmohome_products.xml"
         try:
         try:
             with open(file, 'rb') as f:
             with open(file, 'rb') as f:
                 return HttpResponse(f.read(), content_type='text/xml')
                 return HttpResponse(f.read(), content_type='text/xml')