router.tpl 1004 Bytes
Newer Older
wanli's avatar
wanli committed
1 2 3 4
# -*- coding: utf-8 -*-

from flask import Blueprint
from flask_restful import Api
wanli's avatar
wanli committed
5 6 7
{%- for item in config %}
from . import {{item["name"]}}
{%- endfor %}
wanli's avatar
wanli committed
8 9 10 11 12

api_v1 = Blueprint('api_v1', __name__)

api = Api(api_v1)

13 14 15 16 17 18
{%- for item in config %}
{%- if "restful" in item.get("view") and item.get("view").get("restful") == False %}
{%- for r in item.get("view").get("routes", []) %}
api.add_resource({{ item['name'] }}.{{ r.get('name') | capitalize }}, '{{ r.get("path") }}')
{%- endfor %}
{%- else %}
wanli's avatar
wanli committed
19 20
api.add_resource({{ item['name'] }}.{{ item['name'] | letterUpper }}Resource, '/{{ item['name'] }}{{ item['view']['get']['path'] }}'{% if item['view']['get']['endpoint'] %}, endpoint={{ item['view']['get']['endpoint'] }}{% endif %})
api.add_resource({{ item['name'] }}.{{ item['name'] | letterUpper }}ResourceList, '/{{ item['name'] }}{{ item['view']['getList']['path'] }}'{% if item['view']['getList']['endpoint'] %}, endpoint='{{ item['view']['getList']['endpoint'] }}'{% endif %})
21 22
{%- endif %}
{% endfor %}