Skip to content

Panel

Source code in debug_toolbar/panels/__init__.py
 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
class Panel:
    has_content: bool = True

    def __init__(
        self,
        toolbar: "DebugToolbar",
        call_next: RequestResponseEndpoint,
    ) -> None:
        self.toolbar = toolbar
        self.call_next = call_next

    @property
    def panel_id(self) -> str:
        return self.__class__.__name__

    @property
    def enabled(self) -> bool:
        disabled_panels = self.toolbar.settings.DISABLE_PANELS
        panel_path = get_name_from_obj(self)

        disable_panel = (
            panel_path in disabled_panels
            or panel_path.replace(".panel.", ".") in disabled_panels
        )
        if disable_panel:
            default = "off"
        else:
            default = "on"

        return self.toolbar.request.cookies.get(f"dt{self.panel_id}", default) == "on"

    @property
    def nav_title(self) -> str:
        return self.title

    @property
    def nav_subtitle(self) -> str:
        return ""

    @property
    def title(self) -> str:
        raise NotImplementedError

    @property
    def template(self) -> str:
        raise NotImplementedError

    @property
    def content(self) -> str:
        if self.has_content:
            return self.render(**self.get_stats())
        return ""

    def render(self, **context: t.Any) -> str:
        return self.toolbar.render(self.template, **context)

    def url_for(self, name: str, **path_params: t.Any) -> str:
        return str(self.toolbar.request.url_for(name, **path_params))

    @property
    def scripts(self) -> list[str]:
        return []

    async def process_request(self, request: Request) -> Response:
        return await self.call_next(request)

    async def generate_stats(self, request: Request, response: Response) -> Stats:
        return {}

    def get_stats(self) -> Stats:
        return self.toolbar.stats.get(self.panel_id, {})

    async def record_stats(self, request: Request, response: Response) -> None:
        stats = await self.generate_stats(request, response)

        if stats is not None:
            self.toolbar.stats.setdefault(self.panel_id, {}).update(stats)

    async def generate_server_timing(
        self,
        request: Request,
        response: Response,
    ) -> ServerTiming:
        return []

    def get_server_timing_stats(self) -> ServerTiming:
        return self.toolbar.server_timing_stats.get(self.panel_id, [])

    async def record_server_timing(self, request: Request, response: Response) -> None:
        stats = await self.generate_server_timing(request, response)

        if stats is not None:
            st_stats = self.toolbar.server_timing_stats.setdefault(self.panel_id, [])
            st_stats += list(stats)

call_next = call_next instance-attribute

content: str property

enabled: bool property

has_content: bool = True class-attribute instance-attribute

nav_subtitle: str property

nav_title: str property

panel_id: str property

scripts: list[str] property

template: str property

title: str property

toolbar = toolbar instance-attribute

__init__(toolbar, call_next)

Source code in debug_toolbar/panels/__init__.py
18
19
20
21
22
23
24
def __init__(
    self,
    toolbar: "DebugToolbar",
    call_next: RequestResponseEndpoint,
) -> None:
    self.toolbar = toolbar
    self.call_next = call_next

generate_server_timing(request, response) async

Source code in debug_toolbar/panels/__init__.py
93
94
95
96
97
98
async def generate_server_timing(
    self,
    request: Request,
    response: Response,
) -> ServerTiming:
    return []

generate_stats(request, response) async

Source code in debug_toolbar/panels/__init__.py
81
82
async def generate_stats(self, request: Request, response: Response) -> Stats:
    return {}

get_server_timing_stats()

Source code in debug_toolbar/panels/__init__.py
100
101
def get_server_timing_stats(self) -> ServerTiming:
    return self.toolbar.server_timing_stats.get(self.panel_id, [])

get_stats()

Source code in debug_toolbar/panels/__init__.py
84
85
def get_stats(self) -> Stats:
    return self.toolbar.stats.get(self.panel_id, {})

process_request(request) async

Source code in debug_toolbar/panels/__init__.py
78
79
async def process_request(self, request: Request) -> Response:
    return await self.call_next(request)

record_server_timing(request, response) async

Source code in debug_toolbar/panels/__init__.py
103
104
105
106
107
108
async def record_server_timing(self, request: Request, response: Response) -> None:
    stats = await self.generate_server_timing(request, response)

    if stats is not None:
        st_stats = self.toolbar.server_timing_stats.setdefault(self.panel_id, [])
        st_stats += list(stats)

record_stats(request, response) async

Source code in debug_toolbar/panels/__init__.py
87
88
89
90
91
async def record_stats(self, request: Request, response: Response) -> None:
    stats = await self.generate_stats(request, response)

    if stats is not None:
        self.toolbar.stats.setdefault(self.panel_id, {}).update(stats)

render(**context)

Source code in debug_toolbar/panels/__init__.py
68
69
def render(self, **context: t.Any) -> str:
    return self.toolbar.render(self.template, **context)

url_for(name, **path_params)

Source code in debug_toolbar/panels/__init__.py
71
72
def url_for(self, name: str, **path_params: t.Any) -> str:
    return str(self.toolbar.request.url_for(name, **path_params))