urls.py 2.38 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
3
from django.conf.urls import include
from django.urls import re_path
4
from rest_framework.routers import DefaultRouter, DynamicRoute, Route
Kenzo-Hugo Hillion's avatar
Kenzo-Hugo Hillion committed
5

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

8
from metagenedb.api.catalog.views.celery_test import test_task_view
9

Kenzo-Hugo Hillion's avatar
Kenzo-Hugo Hillion committed
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
56
57
58
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()
59
60
api_router.register(r'functions', views.FunctionViewSet, basename='functions')
api_router.register(r'kegg-orthologies', views.KeggOrthologyViewSet, basename='kegg-orthologies')
61
api_router.register(r'eggnogs', views.EggNOGViewSet, basename='eggnogs')
62
63
api_router.register(r'genes', views.GeneViewSet, basename='genes')
api_router.register(r'taxonomy', views.TaxonomyViewSet, basename='taxonomy')
64
api_router.register(r'statistics', views.StatisticsViewSet, basename='statistics')
Kenzo-Hugo Hillion's avatar
Kenzo-Hugo Hillion committed
65

66

Kenzo-Hugo Hillion's avatar
Kenzo-Hugo Hillion committed
67
urlpatterns = [
Kenzo-Hugo Hillion's avatar
Kenzo-Hugo Hillion committed
68
    re_path(r'v1/', include((api_router.urls, 'v1'))),
69
    path('admin/', include(('metagenedb.api.catalog.admin_urls', 'admin'))),
70
    path('celery-task-test/', test_task_view, name='celery-task-test'),
Kenzo-Hugo Hillion's avatar
Kenzo-Hugo Hillion committed
71
]