-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathurls.py
117 lines (101 loc) · 4.21 KB
/
urls.py
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
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
"""Conreq URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.conf import settings
from django.contrib import admin
from django.contrib.auth import views as auth_views
from django.urls import include, path
from django.views.generic.base import RedirectView
from conreq.utils.environment import get_base_url, get_debug
from conreq.utils.generic import list_modules_with
APPS_DIR = getattr(settings, "APPS_DIR")
DEBUG = get_debug()
BASE_URL = get_base_url()
urlpatterns = [
path("", include("conreq.core.base.urls")),
path("", include("conreq.core.pwa.urls")),
path(
"sign_in/",
auth_views.LoginView.as_view(template_name="registration/sign_in.html"),
name="sign_in",
),
path("sign_out/", auth_views.logout_then_login, name="sign_out"),
path("sign_up/", include("conreq.core.sign_up.urls")),
path("request/", include("conreq.core.user_requests.urls")),
path("password_reset/", include("conreq.core.password_reset.urls")),
# Viewport Locations
path("discover/", include("conreq.core.discover.urls")),
path("more_info/", include("conreq.core.more_info.urls")),
path("report_issue/", include("conreq.core.issue_reporting.urls")),
path("search/", include("conreq.core.search.urls")),
path("manage_users/", include("conreq.core.manage_users.urls")),
path("server_settings/", include("conreq.core.server_settings.urls")),
path("api/v1/", include("conreq.core.api.urls")),
]
# Add User Installed Apps URLS
for app_name, module_path in list_modules_with(APPS_DIR, "urls"):
urlpatterns.insert(0, path(app_name + "/", include(module_path)))
# Debug tools
if DEBUG:
# Performance analysis tool
urlpatterns.append(path("silk/", include("silk.urls", namespace="silk")))
# Ability to edit the DB from admin/
urlpatterns.append(path("admin/docs/", include("django.contrib.admindocs.urls")))
urlpatterns.append(path("admin/", admin.site.urls))
# Django Rest Framework documentation (Swagger and Redoc)
# pylint: disable=ungrouped-imports
from django.urls import re_path
from drf_yasg import openapi
from drf_yasg.views import get_schema_view
from rest_framework import permissions
SchemaView = get_schema_view(
openapi.Info(
title="Conreq API Endpoints",
default_version="v1",
description="""
Outline for all endpoints available within this Conreq instance.
All endpoints require an API key either in **HTTP Header (Authorization: Api-Key)** or in the **URL Parameter (apikey)**.
Token Authentication is performed using **HTTP Header (Authorization: Token)**. Session Authentication can alternatively be performed.
""",
contact=openapi.Contact(email="[email protected]"),
license=openapi.License(name="GPL-3.0 License"),
),
public=True,
permission_classes=[permissions.AllowAny],
)
docs_urlpatterns = [
re_path(
r"^swagger(?P<format>\.json|\.yaml)$",
SchemaView.without_ui(cache_timeout=0),
name="schema-json",
),
re_path(
r"^swagger/$",
SchemaView.with_ui("swagger", cache_timeout=0),
name="schema-swagger-ui",
),
re_path(
r"^redoc/$",
SchemaView.with_ui("redoc", cache_timeout=0),
name="schema-redoc",
),
]
for pattern in docs_urlpatterns:
urlpatterns.append(pattern)
# Wrap the urlpatterns in BASE_URL if required
if BASE_URL:
urlpatterns = [
path("", RedirectView.as_view(url=BASE_URL)),
path(BASE_URL[1:] + "/", include(urlpatterns)),
]