urls.py 5.48 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
#!/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/.           #
#                                                                             #
###############################################################################

28

André Anjos's avatar
André Anjos committed
29
from django.conf import settings
30
from django.contrib import admin
André Anjos's avatar
André Anjos committed
31
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
32 33
from django.urls import include
from django.urls import path
34
from drf_yasg import openapi
Samuel GAIST's avatar
Samuel GAIST committed
35 36
from drf_yasg.views import get_schema_view
from rest_framework import permissions
37
from two_factor.urls import urlpatterns as tfa_urls
38

André Anjos's avatar
André Anjos committed
39
from .navigation import urls as navigation_urls
Samuel GAIST's avatar
Samuel GAIST committed
40
from .ui import urls as ui_urls
André Anjos's avatar
André Anjos committed
41 42 43

admin.autodiscover()

44 45 46 47

schema_view = get_schema_view(
    openapi.Info(
        title="BEAT API",
Samuel GAIST's avatar
Samuel GAIST committed
48
        default_version="v1",
49 50 51 52 53 54
        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,
55
    permission_classes=(permissions.IsAuthenticated,),
56
)
57

André Anjos's avatar
André Anjos committed
58 59 60 61 62
# Views
unprefixed_patterns = ui_urls.urlpatterns
unprefixed_patterns += navigation_urls.urlpatterns

unprefixed_patterns += [
63
    path("", include(tfa_urls)),
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
    path("algorithms/", include("beat.web.algorithms.urls"),),
    path("libraries/", include("beat.web.libraries.urls"),),
    path("attestations/", include("beat.web.attestations.urls"),),
    path("backend/", include("beat.web.backend.urls"),),
    path("dataformats/", include("beat.web.dataformats.urls"),),
    path("databases/", include("beat.web.databases.urls"),),
    path("experiments/", include("beat.web.experiments.urls"),),
    path("search/", include("beat.web.search.urls"),),
    path("statistics/", include("beat.web.statistics.urls"),),
    path("toolchains/", include("beat.web.toolchains.urls"),),
    path("teams/", include("beat.web.team.urls"),),
    path("plotters/", include("beat.web.plotters.urls"),),
    path("reports/", include("beat.web.reports.urls"),),
    path("accounts/", include("beat.web.accounts.urls"),),
    path("admin/", admin.site.urls),
    path(
        r"swagger(<format>\.json|\.yaml)",
Samuel GAIST's avatar
Samuel GAIST committed
81 82 83
        schema_view.without_ui(cache_timeout=0),
        name="schema-json",
    ),
84 85
    path(
        "swagger/",
Samuel GAIST's avatar
Samuel GAIST committed
86 87 88
        schema_view.with_ui("swagger", cache_timeout=0),
        name="schema-swagger-ui",
    ),
89
    path("activity/", include("actstream.urls"),),
Philip ABBET's avatar
Philip ABBET committed
90
]
André Anjos's avatar
André Anjos committed
91 92 93


# API
94 95 96 97 98 99 100 101 102 103 104 105 106 107
api_patterns = [
    path("algorithms/", include("beat.web.algorithms.api_urls"),),
    path("attestations/", include("beat.web.attestations.api_urls"),),
    path("backend/", include("beat.web.backend.api_urls"),),
    path("teams/", include("beat.web.team.api_urls"),),
    path("databases/", include("beat.web.databases.api_urls"),),
    path("dataformats/", include("beat.web.dataformats.api_urls"),),
    path("experiments/", include("beat.web.experiments.api_urls"),),
    path("libraries/", include("beat.web.libraries.api_urls"),),
    path("search/", include("beat.web.search.api_urls"),),
    path("toolchains/", include("beat.web.toolchains.api_urls"),),
    path("plotters/", include("beat.web.plotters.api_urls"),),
    path("reports/", include("beat.web.reports.api_urls"),),
    path("accounts/", include("beat.web.accounts.api_urls"),),
Philip ABBET's avatar
Philip ABBET committed
108
]
André Anjos's avatar
André Anjos committed
109

110
unprefixed_patterns += [path("api/v1/", include(api_patterns))]
André Anjos's avatar
André Anjos committed
111 112

# Process an eventual prefix in the URLs
113
if settings.URL_PREFIX not in ["", "/"]:
Samuel GAIST's avatar
Samuel GAIST committed
114
    urlpatterns = [
115
        path("%s/" % settings.URL_PREFIX[1:], include(unprefixed_patterns)),
Samuel GAIST's avatar
Samuel GAIST committed
116
    ]
André Anjos's avatar
André Anjos committed
117
else:
Samuel GAIST's avatar
Samuel GAIST committed
118
    urlpatterns = unprefixed_patterns
André Anjos's avatar
André Anjos committed
119 120 121

# Static files (only working during development, when settings.DEBUG is True)
urlpatterns += staticfiles_urlpatterns()
122 123 124


# ONLY DURING THE TESTS: Custom error 500 view
Samuel GAIST's avatar
Samuel GAIST committed
125 126
if getattr(settings, "TEST_CONFIGURATION", False):
    handler500 = "beat.web.ui.views.empty_error500_for_tests"