paperless-ngx/src/paperless/urls.py

115 lines
3.4 KiB
Python
Raw Normal View History

2020-11-17 22:31:43 +01:00
from django.conf.urls import include
2015-12-20 19:23:33 +00:00
from django.contrib import admin
from django.contrib.auth.decorators import login_required
2020-11-07 12:47:17 +01:00
from django.urls import path, re_path
2020-11-03 14:47:42 +01:00
from django.views.decorators.csrf import csrf_exempt
2020-10-29 00:36:39 +01:00
from django.views.generic import RedirectView
from rest_framework.authtoken import views
2016-02-16 09:28:34 +00:00
from rest_framework.routers import DefaultRouter
2021-01-02 00:45:23 +01:00
from django.utils.translation import gettext_lazy as _
2020-11-07 12:47:17 +01:00
from paperless.consumers import StatusConsumer
2016-02-16 09:28:34 +00:00
from documents.views import (
2018-01-06 18:51:10 +00:00
CorrespondentViewSet,
DocumentViewSet,
LogViewSet,
2018-09-05 15:25:14 +02:00
TagViewSet,
DocumentTypeViewSet,
SearchView,
2020-10-27 17:07:13 +01:00
IndexView,
2020-10-31 00:56:20 +01:00
SearchAutoCompleteView,
StatisticsView,
2020-12-11 14:30:18 +01:00
PostDocumentView,
SavedViewViewSet,
2020-12-27 12:43:05 +01:00
BulkEditView,
SelectionDataView
2018-09-25 16:09:33 +02:00
)
2020-11-12 21:09:45 +01:00
from paperless.views import FaviconView
2016-02-16 09:28:34 +00:00
api_router = DefaultRouter()
api_router.register(r"correspondents", CorrespondentViewSet)
api_router.register(r"document_types", DocumentTypeViewSet)
api_router.register(r"documents", DocumentViewSet)
api_router.register(r"logs", LogViewSet)
api_router.register(r"tags", TagViewSet)
2020-12-12 15:46:56 +01:00
api_router.register(r"saved_views", SavedViewViewSet)
2016-01-01 16:13:59 +00:00
2015-12-20 19:23:33 +00:00
urlpatterns = [
2020-11-21 15:34:30 +01:00
re_path(r"^api/", include([
re_path(r"^auth/",
include(('rest_framework.urls', 'rest_framework'),
namespace="rest_framework")),
2016-02-21 00:14:50 +00:00
2020-11-21 15:34:30 +01:00
re_path(r"^search/autocomplete/",
SearchAutoCompleteView.as_view(),
name="autocomplete"),
re_path(r"^search/",
SearchView.as_view(),
name="search"),
re_path(r"^statistics/",
StatisticsView.as_view(),
name="statistics"),
re_path(r"^documents/post_document/", PostDocumentView.as_view(),
name="post_document"),
2020-12-11 14:30:18 +01:00
re_path(r"^documents/bulk_edit/", BulkEditView.as_view(),
name="bulk_edit"),
2020-12-27 12:43:05 +01:00
re_path(r"^documents/selection_data/", SelectionDataView.as_view(),
name="selection_data"),
path('token/', views.obtain_auth_token)
2020-11-21 15:34:30 +01:00
] + api_router.urls)),
2020-11-17 22:31:43 +01:00
re_path(r"^favicon.ico$", FaviconView.as_view(), name="favicon"),
2020-11-17 22:31:43 +01:00
re_path(r"admin/", admin.site.urls),
2018-01-06 18:51:16 +00:00
2020-11-21 15:34:30 +01:00
re_path(r"^fetch/", include([
re_path(
r"^doc/(?P<pk>\d+)$",
RedirectView.as_view(url='/api/documents/%(pk)s/download/'),
),
re_path(
r"^thumb/(?P<pk>\d+)$",
RedirectView.as_view(url='/api/documents/%(pk)s/thumb/'),
),
re_path(
r"^preview/(?P<pk>\d+)$",
RedirectView.as_view(url='/api/documents/%(pk)s/preview/'),
),
])),
2020-11-21 15:34:30 +01:00
re_path(r"^push$", csrf_exempt(
RedirectView.as_view(url='/api/documents/post_document/'))),
# Frontend assets TODO: this is pretty bad, but it works.
path('assets/<path:path>',
2021-01-02 01:19:01 +01:00
RedirectView.as_view(url='/static/frontend/en-US/assets/%(path)s')),
# TODO: with localization, this is even worse! :/
2020-11-21 15:34:30 +01:00
# login, logout
path('accounts/', include('django.contrib.auth.urls')),
2020-10-29 00:36:39 +01:00
# Root of the Frontent
2020-11-17 22:31:43 +01:00
re_path(r".*", login_required(IndexView.as_view())),
2020-10-26 00:35:24 +01:00
]
2016-02-08 23:46:16 +00:00
2020-11-07 12:47:17 +01:00
websocket_urlpatterns = [
re_path(r'ws/status/$', StatusConsumer.as_asgi()),
]
# Text in each page's <h1> (and above login form).
2020-11-13 22:06:09 +01:00
admin.site.site_header = 'Paperless-ng'
# Text at the end of each page's <title>.
2020-11-13 22:06:09 +01:00
admin.site.site_title = 'Paperless-ng'
# Text at the top of the admin index page.
2021-01-02 00:45:23 +01:00
admin.site.index_title = _('Paperless-ng administration')