|
@@ -0,0 +1,28 @@
|
|
|
|
+import requests
|
|
|
|
+
|
|
|
|
+from rest_framework import views
|
|
|
|
+from ..serializers import XmlGeneratorSerializer
|
|
|
|
+from rest_framework.request import Request
|
|
|
|
+import xml.etree.ElementTree as ElementTree
|
|
|
|
+from ..models import XmlGeneratorModel
|
|
|
|
+from django.http import JsonResponse
|
|
|
|
+from ..parsers.parse_xml_to_json import parse_xml_to_json
|
|
|
|
+
|
|
|
|
+class XmlGeneratorView(views.APIView):
|
|
|
|
+ @classmethod
|
|
|
|
+ def get(cls, request: Request, *args, **kwargs) -> JsonResponse:
|
|
|
|
+ return JsonResponse({}, safe=False)
|
|
|
|
+
|
|
|
|
+ @classmethod
|
|
|
|
+ def post(cls, request: Request, *args, **kwargs) -> JsonResponse:
|
|
|
|
+ url = request.data.get('url')
|
|
|
|
+
|
|
|
|
+ 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)
|
|
|
|
+
|
|
|
|
+ #serialized_response = XmlGeneratorSerializer.for_api()
|
|
|
|
+ return JsonResponse(response_json, safe=False)
|