diff --git a/api/api_methods.py b/api/api_methods.py index e0b0058..51cc9b0 100644 --- a/api/api_methods.py +++ b/api/api_methods.py @@ -221,6 +221,10 @@ class ApiOrder: ] }) + @staticmethod + def create(self): + pass + def api_call_method(method_name, params: dict): try: @@ -237,10 +241,30 @@ def api_call_method(method_name, params: dict): def api_get_documentation(): - # { - # "name": p["name"], - # "type": p["type"], - # "description": p["description"], - # "required": p["required"] - # } - return [] \ No newline at end of file + def _translate_type(t): + _types = { + str: "str", + int: "int", + UserToken: "token" + } + if t in _types: + return _types[t] + else: + return str(t) + + out = [] + for m in api_methods_dict: + out.append({ + "name": m, + "doc": api_methods_dict[m]["doc"], + "returns": api_methods_dict[m]["returns"], + "params": [ + { + "name": p["name"], + "type": _translate_type(p["type"]), + "description": p["description"], + "required": p["required"] + } for p in api_methods_dict[m]["params"] + ] + }) + return out diff --git a/api/api_utils.py b/api/api_utils.py index 81ca559..d27f244 100644 --- a/api/api_utils.py +++ b/api/api_utils.py @@ -36,8 +36,8 @@ def api_get_param_str(params: dict, name: str, required=True, default=""): def api_get_access_token(params: dict, unused_name, required=True): - token = api_get_param_str(params, "access_token", required)[0] - print(f"checking token '{token}'") + token = api_get_param_str(params, "access_token", required) + # print(f"checking token '{token}'") return UserToken.get_by_token(token) @@ -93,7 +93,7 @@ def api_method(func_name, doc="", params: list or None = None, returns=""): "doc": doc, "params": params, "func": wrapper, - "return": returns + "returns": returns } return wrapper diff --git a/api/views.py b/api/views.py index 3b4431e..4aafc54 100644 --- a/api/views.py +++ b/api/views.py @@ -8,16 +8,6 @@ from .api_errors import * def view_methods(request): - methods = [] - - def __make_param(p): - return { - "name": p["name"], - "type": p["type"], - "description": p["description"], - "required": p["required"] - } - methods = api_get_documentation() return render(request, 'api/index.html', {'api_methods': methods}) @@ -29,9 +19,13 @@ def call_method(request, method_name): params = request.POST else: return HttpResponseBadRequest() + api_params = {} + for p in params: + # защита от нескольких параметров с одним именем + api_params[p] = params[p] - out = api_call_method(method_name, params) + out = api_call_method(method_name, api_params) - response = HttpResponse(json.dumps(out, ensure_ascii=False)) + response = HttpResponse(json.dumps(out, ensure_ascii=False, indent=4)) response.headers["Content-type"] = "application/json; charset=utf-8" return response diff --git a/templates/base.html b/templates/base.html index 9131023..9889f65 100644 --- a/templates/base.html +++ b/templates/base.html @@ -45,7 +45,7 @@