urls.py 1.2 KB
Newer Older
1
from django.conf.urls import include, url
2 3

from backend_app.config.viewsets import get_viewsets_info
4
from backend_app.checks import check_viewsets
5 6 7
from rest_framework import routers
from rest_framework.documentation import include_docs_urls

8 9 10
STANDARD_VIEWSETS = get_viewsets_info(requires_testing="smart", is_api_view=False)
API_VIEW_VIEWSETS = get_viewsets_info(requires_testing="smart", is_api_view=True)

11
check_viewsets(map(lambda v: v.Viewset, STANDARD_VIEWSETS))
12

13 14 15
#######
# Building the API routing
#######
16

17
urlpatterns = [url(r"^api-docs/", include_docs_urls(title="Outgoing API"))]
18 19
router = routers.DefaultRouter()

20
for api_obj in STANDARD_VIEWSETS:
Florent Chehab's avatar
Florent Chehab committed
21

22 23
    # Creating the correct router entry
    str_url = api_obj.api_end_point
24
    if api_obj.api_attr is not None:
25
        str_url += "/{}".format(api_obj.api_attr)
26
    if api_obj.api_name is not None:
27 28 29
        router.register(str_url, api_obj.Viewset, api_obj.api_name)
    else:
        router.register(str_url, api_obj.Viewset)
30

Florent Chehab's avatar
Florent Chehab committed
31
# Add all the endpoints for the base api
32 33
urlpatterns.append(url(r"^api/", include(router.urls)))

34
for api_obj in API_VIEW_VIEWSETS:
35 36 37
    urlpatterns.append(
        url(r"^api/{}/".format(api_obj.api_end_point), api_obj.Viewset.as_view())
    )