Plain is headed towards 1.0! Subscribe for development updates →

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