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

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

7 8 9
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)

10

11 12 13
#######
# Building the API routing
#######
14

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

18
for api_obj in STANDARD_VIEWSETS:
Florent Chehab's avatar
Florent Chehab committed
19

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

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

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