11import contextlib
22import json
33
4- from django .http .request import RawPostDataException
4+ from django .http import HttpResponse , QueryDict
5+ from django .http .request import HttpRequest , RawPostDataException
56from django .template .loader import render_to_string
67from django .templatetags .static import static
7- from django .urls import path
8+ from django .urls import URLPattern , path
89from django .utils import timezone
910from django .utils .translation import gettext_lazy as _
1011
@@ -21,42 +22,42 @@ class HistoryPanel(Panel):
2122 nav_title = _ ("History" )
2223 template = "debug_toolbar/panels/history.html"
2324
24- def get_headers (self , request ) :
25- headers = super ().get_headers (request )
25+ def get_headers (self , request : HttpRequest ) -> dict :
26+ headers : dict = super ().get_headers (request )
2627 observe_request = self .toolbar .get_observe_request ()
2728 request_id = self .toolbar .request_id
2829 if request_id and observe_request (request ):
2930 headers ["djdt-request-id" ] = request_id
3031 return headers
3132
3233 @property
33- def enabled (self ):
34+ def enabled (self ) -> bool :
3435 # Do not show the history panel if the panels are rendered on request
3536 # rather than loaded via ajax.
3637 return super ().enabled and not self .toolbar .should_render_panels ()
3738
3839 @property
39- def is_historical (self ):
40+ def is_historical (self ) -> bool :
4041 """The HistoryPanel should not be included in the historical panels."""
4142 return False
4243
4344 @classmethod
44- def get_urls (cls ):
45+ def get_urls (cls ) -> list [ URLPattern ] :
4546 return [
4647 path ("history_sidebar/" , views .history_sidebar , name = "history_sidebar" ),
4748 path ("history_refresh/" , views .history_refresh , name = "history_refresh" ),
4849 ]
4950
5051 @property
51- def nav_subtitle (self ):
52+ def nav_subtitle (self ) -> str :
5253 return self .get_stats ().get ("request_url" , "" )
5354
54- def generate_stats (self , request , response ) :
55+ def generate_stats (self , request : HttpRequest , response : HttpResponse ) -> None :
5556 try :
5657 if request .method == "GET" :
57- data = request .GET .copy ()
58+ data : QueryDict = request .GET .copy ()
5859 else :
59- data = request .POST .copy ()
60+ data : QueryDict = request .POST .copy ()
6061 # GraphQL tends to not be populated in POST. If the request seems
6162 # empty, check if it's a JSON request.
6263 if (
@@ -82,12 +83,12 @@ def generate_stats(self, request, response):
8283 )
8384
8485 @property
85- def content (self ):
86+ def content (self ) -> str :
8687 """Content of the panel when it's displayed in full screen.
8788
8889 Fetch every store for the toolbar and include it in the template.
8990 """
90- toolbar_history = {}
91+ toolbar_history : dict [ str , dict ] = {}
9192 for request_id in reversed (self .toolbar .store .request_ids ()):
9293 toolbar_history [request_id ] = {
9394 "history_stats" : self .toolbar .store .panel (
@@ -113,7 +114,7 @@ def content(self):
113114 )
114115
115116 @property
116- def scripts (self ):
117- scripts = super ().scripts
117+ def scripts (self ) -> list [ str ] :
118+ scripts : list [ str ] = super ().scripts
118119 scripts .append (static ("debug_toolbar/js/history.js" ))
119120 return scripts
0 commit comments