|
@@ -2,9 +2,12 @@ import requests
|
|
|
|
|
|
from rest_framework import views
|
|
from rest_framework import views
|
|
from rest_framework.request import Request
|
|
from rest_framework.request import Request
|
|
-import xml.etree.ElementTree as ElementTree
|
|
|
|
|
|
+
|
|
from django.http import JsonResponse
|
|
from django.http import JsonResponse
|
|
from ..parsers.parse_xml_to_json import parse_xml_to_json
|
|
from ..parsers.parse_xml_to_json import parse_xml_to_json
|
|
|
|
+from ..Clients.PrestaShopClient import PrestaShopClient
|
|
|
|
+from ..parsers.PrestaShopParser import PrestaShopParser
|
|
|
|
+
|
|
|
|
|
|
class XmlGeneratorView(views.APIView):
|
|
class XmlGeneratorView(views.APIView):
|
|
@classmethod
|
|
@classmethod
|
|
@@ -14,13 +17,13 @@ class XmlGeneratorView(views.APIView):
|
|
@classmethod
|
|
@classmethod
|
|
def post(cls, request: Request, *args, **kwargs) -> JsonResponse:
|
|
def post(cls, request: Request, *args, **kwargs) -> JsonResponse:
|
|
url = request.data.get('url')
|
|
url = request.data.get('url')
|
|
|
|
+ token = request.data.get('token')
|
|
|
|
+
|
|
|
|
+ prestashop_client = PrestaShopClient(base_url=url, token=token)
|
|
|
|
|
|
- if url:
|
|
|
|
- response = requests.get(url)
|
|
|
|
- if response and response.status_code == 200:
|
|
|
|
- response_xml_as_string = response.content
|
|
|
|
- response_xml = ElementTree.fromstring(response_xml_as_string)
|
|
|
|
- response_json = parse_xml_to_json(response_xml)
|
|
|
|
|
|
+ products_response = prestashop_client.get_products({'limit': 4})
|
|
|
|
+ categories_response = prestashop_client.get_categories({'limit': 4})
|
|
|
|
+ categories = PrestaShopParser.parse_categories(categories_response)
|
|
|
|
|
|
- #serialized_response = XmlGeneratorSerializer.for_api()
|
|
|
|
|
|
+ response_json = {}
|
|
return JsonResponse(response_json, safe=False)
|
|
return JsonResponse(response_json, safe=False)
|