urls.py 6.76 KB
Newer Older
André Anjos's avatar
André Anjos committed
1
2
3
4
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
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :

###############################################################################
#                                                                             #
# Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/           #
# Contact: beat.support@idiap.ch                                              #
#                                                                             #
# This file is part of the beat.web module of the BEAT platform.              #
#                                                                             #
# Commercial License Usage                                                    #
# Licensees holding valid commercial BEAT licenses may use this file in       #
# accordance with the terms contained in a written agreement between you      #
# and Idiap. For further information contact tto@idiap.ch                     #
#                                                                             #
# Alternatively, this file may be used under the terms of the GNU Affero      #
# Public License version 3 as published by the Free Software and appearing    #
# in the file LICENSE.AGPL included in the packaging of this file.            #
# The BEAT platform is distributed in the hope that it will be useful, but    #
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY  #
# or FITNESS FOR A PARTICULAR PURPOSE.                                        #
#                                                                             #
# You should have received a copy of the GNU Affero Public License along      #
# with the BEAT platform. If not, see http://www.gnu.org/licenses/.           #
#                                                                             #
###############################################################################

from django.conf.urls import url, include
from django.conf import settings
from django.views.generic import TemplateView
from django.contrib.staticfiles.urls import staticfiles_urlpatterns

33
34
35
from rest_framework import permissions
from drf_yasg.views import get_schema_view
from drf_yasg import openapi
36

André Anjos's avatar
André Anjos committed
37
38
39
from .ui import urls as ui_urls
from .navigation import urls as navigation_urls

Samuel GAIST's avatar
Samuel GAIST committed
40
41
42
43
try:
  from urlparse import urlparse
except ImportError:
  from urllib.parse import urlparse
André Anjos's avatar
André Anjos committed
44
45
46
47

from django.contrib import admin
admin.autodiscover()

48
49
50
51
52
53
54
55
56
57
58

schema_view = get_schema_view(
    openapi.Info(
        title="BEAT API",
        default_version='v1',
        description="REST API for BEAT platform",
        terms_of_service="https://gitlab.idiap.ch/beat/beat.web/blob/master/LICENSE.AGPL",
        contact=openapi.Contact(email="beat.support@idiap.ch"),
        license=openapi.License(name="AGPLv3 License"),
    ),
    public=True,
59
    permission_classes=(permissions.IsAuthenticated,),
60
)
61

André Anjos's avatar
André Anjos committed
62
63
64
65
66
67
68
# Views
unprefixed_patterns = ui_urls.urlpatterns
unprefixed_patterns += navigation_urls.urlpatterns

unprefixed_patterns += [

    url(r'^algorithms/',
Philip ABBET's avatar
Philip ABBET committed
69
        include('beat.web.algorithms.urls', namespace='algorithms'),
70
        ),
André Anjos's avatar
André Anjos committed
71
72

    url(r'^libraries/',
Philip ABBET's avatar
Philip ABBET committed
73
        include('beat.web.libraries.urls', namespace='libraries'),
74
        ),
André Anjos's avatar
André Anjos committed
75
76

    url(r'^attestations/',
Philip ABBET's avatar
Philip ABBET committed
77
        include('beat.web.attestations.urls', namespace='attestations'),
78
        ),
André Anjos's avatar
André Anjos committed
79
80

    url(r'^backend/',
Philip ABBET's avatar
Philip ABBET committed
81
        include('beat.web.backend.urls', namespace='backend'),
82
        ),
André Anjos's avatar
André Anjos committed
83
84

    url(r'^dataformats/',
Philip ABBET's avatar
Philip ABBET committed
85
        include('beat.web.dataformats.urls', namespace='dataformats'),
86
        ),
André Anjos's avatar
André Anjos committed
87
88

    url(r'^databases/',
Philip ABBET's avatar
Philip ABBET committed
89
        include('beat.web.databases.urls', namespace='databases'),
90
        ),
André Anjos's avatar
André Anjos committed
91
92

    url(r'^experiments/',
Philip ABBET's avatar
Philip ABBET committed
93
        include('beat.web.experiments.urls', namespace='experiments'),
94
        ),
André Anjos's avatar
André Anjos committed
95
96

    url(r'^search/',
Philip ABBET's avatar
Philip ABBET committed
97
        include('beat.web.search.urls', namespace='search'),
98
        ),
André Anjos's avatar
André Anjos committed
99
100

    url(r'^statistics/',
Philip ABBET's avatar
Philip ABBET committed
101
        include('beat.web.statistics.urls', namespace='statistics'),
102
        ),
André Anjos's avatar
André Anjos committed
103
104

    url(r'^toolchains/',
Philip ABBET's avatar
Philip ABBET committed
105
        include('beat.web.toolchains.urls', namespace='toolchains'),
106
        ),
André Anjos's avatar
André Anjos committed
107
108

    url(r'^teams/',
Philip ABBET's avatar
Philip ABBET committed
109
        include('beat.web.team.urls', namespace='teams'),
110
        ),
André Anjos's avatar
André Anjos committed
111
112

    url(r'^plotters/',
Philip ABBET's avatar
Philip ABBET committed
113
        include('beat.web.plotters.urls', namespace='plotters'),
114
        ),
André Anjos's avatar
André Anjos committed
115
116

    url(r'^reports/',
Philip ABBET's avatar
Philip ABBET committed
117
        include('beat.web.reports.urls', namespace='reports'),
118
        ),
André Anjos's avatar
André Anjos committed
119
120
121
122
123
124
125

    url(r'^accounts/',
        include('beat.web.accounts.urls', namespace='accounts'),
        ),

    url(r'^admin/', include(admin.site.urls)),

126
127
128
129
130
    url(r'^swagger(?P<format>\.json|\.yaml)$',
        schema_view.without_ui(cache_timeout=0), name='schema-json'),
    
    url(r'^swagger/$', 
        schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
André Anjos's avatar
André Anjos committed
131
132
133
134
135

    url(r'^activity/',
        include('actstream.urls'),
        ),

Philip ABBET's avatar
Philip ABBET committed
136
]
André Anjos's avatar
André Anjos committed
137
138
139
140
141
142


# API
unprefixed_patterns += [

    url(r'^api/v1/teams/',
Philip ABBET's avatar
Philip ABBET committed
143
        include('beat.web.team.api_urls', namespace='api_teams'),
144
        ),
André Anjos's avatar
André Anjos committed
145
146

    url(r'^api/v1/algorithms/',
Philip ABBET's avatar
Philip ABBET committed
147
        include('beat.web.algorithms.api_urls', namespace='api_algorithms'),
148
        ),
André Anjos's avatar
André Anjos committed
149
150

    url(r'^api/v1/attestations/',
151
152
153
        include('beat.web.attestations.api_urls',
                namespace='api_attestations'),
        ),
André Anjos's avatar
André Anjos committed
154
155

    url(r'^api/v1/backend/',
Philip ABBET's avatar
Philip ABBET committed
156
        include('beat.web.backend.api_urls', namespace='api_backend'),
157
        ),
André Anjos's avatar
André Anjos committed
158
159

    url(r'^api/v1/databases/',
Philip ABBET's avatar
Philip ABBET committed
160
        include('beat.web.databases.api_urls', namespace='api_databases'),
161
        ),
André Anjos's avatar
André Anjos committed
162
163

    url(r'^api/v1/dataformats/',
Philip ABBET's avatar
Philip ABBET committed
164
        include('beat.web.dataformats.api_urls', namespace='api_dataformats'),
165
        ),
André Anjos's avatar
André Anjos committed
166
167

    url(r'^api/v1/experiments/',
Philip ABBET's avatar
Philip ABBET committed
168
        include('beat.web.experiments.api_urls', namespace='api_experiments'),
169
        ),
André Anjos's avatar
André Anjos committed
170
171

    url(r'^api/v1/libraries/',
Philip ABBET's avatar
Philip ABBET committed
172
        include('beat.web.libraries.api_urls', namespace='api_libraries'),
173
        ),
André Anjos's avatar
André Anjos committed
174
175

    url(r'^api/v1/search/',
Philip ABBET's avatar
Philip ABBET committed
176
        include('beat.web.search.api_urls', namespace='api_search'),
177
        ),
André Anjos's avatar
André Anjos committed
178
179

    url(r'^api/v1/toolchains/',
Philip ABBET's avatar
Philip ABBET committed
180
        include('beat.web.toolchains.api_urls', namespace='api_toolchains'),
181
        ),
André Anjos's avatar
André Anjos committed
182
183

    url(r'^api/v1/plotters/',
Philip ABBET's avatar
Philip ABBET committed
184
        include('beat.web.plotters.api_urls', namespace='api_plotters'),
185
        ),
André Anjos's avatar
André Anjos committed
186
187
188
189
190

    url(r'^api/v1/reports/',
        include('beat.web.reports.api_urls', namespace='api_reports'),
        ),

191
192
193
194
    url(r'^api/v1/accounts/',
        include('beat.web.accounts.api_urls', namespace='api_accounts'),
        ),

Philip ABBET's avatar
Philip ABBET committed
195
]
André Anjos's avatar
André Anjos committed
196
197
198
199
200


# Process an eventual prefix in the URLs
parsed_url = urlparse(settings.URL_PREFIX)
if (parsed_url.path != '') and (parsed_url.path != '/'):
201
202
203
  urlpatterns = [
      url(r'^%s/' % parsed_url.path[1:], include(unprefixed_patterns)),
  ]
André Anjos's avatar
André Anjos committed
204
else:
205
  urlpatterns = unprefixed_patterns
André Anjos's avatar
André Anjos committed
206
207
208

# Static files (only working during development, when settings.DEBUG is True)
urlpatterns += staticfiles_urlpatterns()
209
210
211
212


# ONLY DURING THE TESTS: Custom error 500 view
if getattr(settings, 'TEST_CONFIGURATION', False):
213
  handler500 = 'beat.web.ui.views.empty_error500_for_tests'