1from plain.http import ResponseRedirect
2from plain.urls import Router, include, path
3
4from .impersonate.urls import ImpersonateRouter
5from .querystats.urls import QuerystatsRouter
6from .views.base import AdminView
7from .views.registry import registry
8
9
10class AdminIndexView(AdminView):
11 template_name = "admin/index.html"
12 title = "Dashboard"
13
14 def get(self):
15 # Slight hack to redirect to the first view that doesn't
16 # require any url params...
17 if views := registry.get_searchable_views():
18 return ResponseRedirect(list(views)[0].get_view_url())
19
20 return super().get()
21
22
23class AdminSearchView(AdminView):
24 template_name = "admin/search.html"
25 title = "Search"
26
27 def get_template_context(self):
28 context = super().get_template_context()
29 context["searchable_views"] = registry.get_searchable_views()
30 context["global_search_query"] = self.request.query_params.get("query", "")
31 return context
32
33
34class AdminRouter(Router):
35 namespace = "admin"
36 urls = [
37 path("search/", AdminSearchView, name="search"),
38 include("impersonate/", ImpersonateRouter),
39 include("querystats/", QuerystatsRouter),
40 include("", registry.get_urls()),
41 path("", AdminIndexView, name="index"),
42 ]