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

4
from metagenedb.api.catalog import views
Kenzo-Hugo Hillion's avatar
Kenzo-Hugo Hillion committed
5
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
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()
55
56
57
58
59
api_router.register(r'functions', views.FunctionViewSet, basename='functions')
api_router.register(r'kegg-orthologies', views.KeggOrthologyViewSet, basename='kegg-orthologies')
api_router.register(r'eggnogs', views.EggNogViewSet, basename='eggnogs')
api_router.register(r'genes', views.GeneViewSet, basename='genes')
api_router.register(r'taxonomy', views.TaxonomyViewSet, basename='taxonomy')
Kenzo-Hugo Hillion's avatar
Kenzo-Hugo Hillion committed
60

61

Kenzo-Hugo Hillion's avatar
Kenzo-Hugo Hillion committed
62
urlpatterns = [
63
    url(r'v1/', include((api_router.urls, 'v1')))
Kenzo-Hugo Hillion's avatar
Kenzo-Hugo Hillion committed
64
]