urls.py 2.21 KB
Newer Older
Kenzo-Hugo Hillion's avatar
Kenzo-Hugo Hillion committed
1
from django.urls import path
Kenzo-Hugo Hillion's avatar
Kenzo-Hugo Hillion committed
2
from django.conf.urls import url, include
3
from rest_framework.routers import DefaultRouter, DynamicRoute, Route
Kenzo-Hugo Hillion's avatar
Kenzo-Hugo Hillion committed
4

5
from metagenedb.api.catalog import views
Kenzo-Hugo Hillion's avatar
Kenzo-Hugo Hillion committed
6
7


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
class CustomRouter(DefaultRouter):

    routes = [
        # List route.
        Route(
            url=r'^{prefix}{trailing_slash}$',
            mapping={
                'get': 'list',
                'put': 'update',
                'post': 'create'
            },
            name='{basename}-list',
            detail=False,
            initkwargs={'suffix': 'List'}
        ),
        # Dynamically generated list routes. Generated using
        # @action(detail=False) decorator on methods of the viewset.
        DynamicRoute(
            url=r'^{prefix}/{url_path}{trailing_slash}$',
            name='{basename}-{url_name}',
            detail=False,
            initkwargs={}
        ),
        # Detail route.
        Route(
            url=r'^{prefix}/{lookup}{trailing_slash}$',
            mapping={
                'get': 'retrieve',
                'put': 'update',
                'patch': 'partial_update',
                'delete': 'destroy'
            },
            name='{basename}-detail',
            detail=True,
            initkwargs={'suffix': 'Instance'}
        ),
        # Dynamically generated detail routes. Generated using
        # @action(detail=True) decorator on methods of the viewset.
        DynamicRoute(
            url=r'^{prefix}/{lookup}/{url_path}{trailing_slash}$',
            name='{basename}-{url_name}',
            detail=True,
            initkwargs={}
        ),
    ]


api_router = CustomRouter()
56
57
api_router.register(r'functions', views.FunctionViewSet, basename='functions')
api_router.register(r'kegg-orthologies', views.KeggOrthologyViewSet, basename='kegg-orthologies')
58
api_router.register(r'eggnogs', views.EggNOGViewSet, basename='eggnogs')
59
60
api_router.register(r'genes', views.GeneViewSet, basename='genes')
api_router.register(r'taxonomy', views.TaxonomyViewSet, basename='taxonomy')
61
api_router.register(r'statistics', views.StatisticsViewSet, basename='statistics')
Kenzo-Hugo Hillion's avatar
Kenzo-Hugo Hillion committed
62

63

Kenzo-Hugo Hillion's avatar
Kenzo-Hugo Hillion committed
64
urlpatterns = [
Kenzo-Hugo Hillion's avatar
Kenzo-Hugo Hillion committed
65
66
    url(r'v1/', include((api_router.urls, 'v1'))),
    path('admin/', include(('metagenedb.api.catalog.admin_urls', 'admin')))
Kenzo-Hugo Hillion's avatar
Kenzo-Hugo Hillion committed
67
]