initial commit

This commit is contained in:
2023-03-06 20:27:57 +03:00
commit b02b9e1811
70 changed files with 2741 additions and 0 deletions

37
api/views.py Executable file
View File

@@ -0,0 +1,37 @@
import json
import traceback
from django.shortcuts import render
from django.http import HttpResponse, HttpResponseBadRequest
from .api_methods import api_call_method, api_get_documentation
def view_methods(request):
methods = api_get_documentation()
return render(request, 'index.html', {'api_methods': methods})
def _default_serializer(obj):
try:
return obj.to_json()
except Exception:
return str(obj)
async def call_method(request, method_name):
if request.method == "GET":
params = request.GET
elif request.method == "POST":
params = request.POST
else:
return HttpResponseBadRequest()
api_params = {}
for p in params:
# защита от нескольких параметров с одним именем
api_params[p] = params[p]
out = await api_call_method(method_name, api_params)
response = HttpResponse(json.dumps(out, default=_default_serializer, ensure_ascii=False, indent=4))
response.headers["Content-type"] = "application/json; charset=utf-8"
return response