Plain is headed towards 1.0! Subscribe for development updates →

 1from plain.http import ResponseRedirect
 2
 3from .base import StaffView
 4from .registry import registry
 5
 6
 7# This will be dashboard view...
 8class StaffIndexView(StaffView):
 9    template_name = "staff/index.html"
10    title = "Dashboards"
11    slug = ""
12
13    def get(self):
14        # If there's exactly one dashboard, redirect straight to it
15        dashboards = registry.registered_dashboards
16        if len(dashboards) == 1:
17            return ResponseRedirect(list(dashboards)[0].get_absolute_url())
18
19        return super().get()
20
21    def get_template_context(self):
22        context = super().get_template_context()
23        context["dashboards"] = registry.registered_dashboards
24        return context
25
26
27class StaffSearchView(StaffView):
28    template_name = "staff/search.html"
29    title = "Search"
30    slug = "search"
31
32    def get_template_context(self):
33        context = super().get_template_context()
34        context["searchable_views"] = registry.get_searchable_views()
35        context["global_search_query"] = self.request.GET.get("query", "")
36        return context