8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-05 01:16:27 +00:00
re2o/api/urls.py

69 lines
2.3 KiB
Python
Raw Normal View History

2018-06-30 01:25:46 +00:00
# -*- mode: python; coding: utf-8 -*-
2020-11-23 16:06:37 +00:00
# Re2o est un logiciel d'administration développé initiallement au Rézo Metz. Il
2018-03-17 17:20:31 +00:00
# se veut agnostique au réseau considéré, de manière à être installable en
# quelques clics.
#
2018-06-17 01:06:58 +00:00
# Copyright © 2018 Maël Kervella
2020-11-23 18:58:55 +00:00
# Copyright © 2020 Corentin Canebier
2018-03-17 17:20:31 +00:00
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program 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. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2018-06-17 01:06:58 +00:00
"""Defines the URLs of the API
2018-03-17 17:20:31 +00:00
2018-06-17 01:06:58 +00:00
A custom router is used to register all the routes. That allows to register
all the URL patterns from the viewsets as a standard router but, the views
can also be register. That way a complete API root page presenting all URLs
can be generated automatically.
"""
2018-03-17 17:20:31 +00:00
2018-04-19 22:00:49 +00:00
from django.conf.urls import url, include
2020-04-21 12:00:52 +00:00
from importlib import import_module
2018-03-17 17:20:31 +00:00
2018-03-17 17:50:03 +00:00
from . import views
2018-06-17 01:06:58 +00:00
from .routers import AllViewsRouter
2020-04-21 12:00:52 +00:00
from django.conf import settings
2018-06-17 01:06:58 +00:00
2018-06-16 19:20:13 +00:00
router = AllViewsRouter()
2020-04-21 12:00:52 +00:00
urls_viewset = []
urls_view = []
2020-11-23 18:58:55 +00:00
urls_functional_view = []
2020-04-21 12:00:52 +00:00
for app in settings.INSTALLED_APPS:
try:
module = import_module(".api.urls", package=app)
urls_viewset += getattr(module, "urls_viewset", [])
urls_view += getattr(module, "urls_view", [])
2020-11-23 18:58:55 +00:00
urls_functional_view += getattr(module, "urls_functional_view", [])
2020-04-21 12:00:52 +00:00
except ImportError:
continue
for _url, viewset, name in urls_viewset:
if name == None:
router.register_viewset(_url, viewset)
else:
router.register_viewset(_url, viewset, basename=name)
for _url, view in urls_view:
router.register_view(_url, view)
2020-11-23 18:58:55 +00:00
for _url, view, name in urls_functional_view:
router.register_functional_view(_url, view, name)
2020-04-21 12:00:52 +00:00
2018-06-17 01:06:58 +00:00
# TOKEN AUTHENTICATION
router.register_view(r"token-auth", views.ObtainExpiringAuthToken)
urlpatterns = [url(r"^", include(router.urls))]