Browse Source

add Model, View, Serializers for xml generator

sxoinas12 2 years ago
parent
commit
d94cf86991

+ 1 - 0
.gitignore

@@ -4,6 +4,7 @@ venv/
 node_modules/
 node_modules/
 __pycache__
 __pycache__
 **/__pycache__
 **/__pycache__
+telecaster/__pycache__/
 *.pyc
 *.pyc
 .pipcache
 .pipcache
 .benchmarks/
 .benchmarks/

+ 8 - 0
.idea/.gitignore

@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml

+ 8 - 0
.idea/modules.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectModuleManager">
+    <modules>
+      <module fileurl="file://$PROJECT_DIR$/.idea/telecaster.iml" filepath="$PROJECT_DIR$/.idea/telecaster.iml" />
+    </modules>
+  </component>
+</project>

+ 17 - 0
.idea/telecaster.iml

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="PYTHON_MODULE" version="4">
+  <component name="NewModuleRootManager">
+    <content url="file://$MODULE_DIR$">
+      <excludeFolder url="file://$MODULE_DIR$/virtualenv" />
+    </content>
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+  </component>
+  <component name="PyDocumentationSettings">
+    <option name="format" value="PLAIN" />
+    <option name="myDocStringFormat" value="Plain" />
+  </component>
+  <component name="TestRunnerService">
+    <option name="PROJECT_TEST_RUNNER" value="py.test" />
+  </component>
+</module>

+ 6 - 0
.idea/vcs.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
+  </component>
+</project>

BIN
telecaster/db.sqlite3


BIN
telecaster/telecaster/__pycache__/settings.cpython-38.pyc


BIN
telecaster/telecaster/__pycache__/urls.cpython-38.pyc


+ 5 - 0
telecaster/telecaster/models/XmlGeneratorModel.py

@@ -0,0 +1,5 @@
+from django.db import models
+
+
+class XmlGeneratorModel:
+    pass

+ 11 - 0
telecaster/telecaster/serializers/XmlGeneratorSerializer.py

@@ -0,0 +1,11 @@
+from rest_framework import serializers
+from ..models import XmlGeneratorModel
+
+
+class XmlGeneratorSerializer(serializers.Serializer):
+    class Meta:
+        model = XmlGeneratorModel
+
+    @classmethod
+    def for_api(validated_data):
+        return validated_data

+ 3 - 0
telecaster/telecaster/serializers/__init__.py

@@ -0,0 +1,3 @@
+from .XmlGeneratorSerializer import XmlGeneratorSerializer
+
+__all__ = ['XmlGeneratorSerializer']

+ 28 - 0
telecaster/telecaster/views/XmlGeneratorView.py

@@ -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)

+ 3 - 0
telecaster/telecaster/views/__init__.py

@@ -0,0 +1,3 @@
+from .XmlGeneratorView import XmlGeneratorView
+
+__all__ = ['XmlGeneratorView']