def history_refresh(request): """Returns the refreshed list of table rows for the History Panel.""" form = HistoryStoreForm(request.GET) if form.is_valid(): requests = [] for id, toolbar in reversed(DebugToolbar._store.items()): requests.append({ "id": id, "content": render_to_string( "debug_toolbar/panels/history_tr.html", { "id": id, "store_context": { "toolbar": toolbar, "form": HistoryStoreForm(initial={"store_id": id}), }, }, ), }) return JsonResponse({"requests": requests}) return HttpResponseBadRequest("Form errors")
def history_sidebar(request): """Returns the selected debug toolbar history snapshot.""" form = HistoryStoreForm(request.GET) if form.is_valid(): store_id = form.cleaned_data["store_id"] toolbar = DebugToolbar.fetch(store_id) exclude_history = form.cleaned_data["exclude_history"] context = {} if toolbar is None: # When the store_id has been popped already due to # RESULTS_CACHE_SIZE return JsonResponse(context) for panel in toolbar.panels: if exclude_history and not panel.is_historical: continue panel_context = {"panel": panel} context[panel.panel_id] = { "button": render_to_string("debug_toolbar/includes/panel_button.html", panel_context), "content": render_to_string("debug_toolbar/includes/panel_content.html", panel_context), } return JsonResponse(context) return HttpResponseBadRequest("Form errors")
def history_refresh(request): """Returns the refreshed list of table rows for the History Panel.""" form = HistoryStoreForm(request.GET) if form.is_valid(): requests = [] # Convert to list to handle mutations happening in parallel for id, toolbar in list(DebugToolbar._store.items()): requests.append({ "id": id, "content": render_to_string( "debug_toolbar/panels/history_tr.html", { "id": id, "store_context": { "toolbar": toolbar, "form": HistoryStoreForm(initial={ "store_id": id, "exclude_history": True, }), }, }, ), }) return JsonResponse({"requests": requests}) return HttpResponseBadRequest("Form errors")
def content(self): """Content of the panel when it's displayed in full screen. Fetch every store for the toolbar and include it in the template. """ stores = {} for id, toolbar in reversed(self.toolbar._store.items()): stores[id] = { "toolbar": toolbar, "form": HistoryStoreForm( initial={"store_id": id, "exclude_history": True} ), } return render_to_string( self.template, { "current_store_id": self.toolbar.store_id, "stores": stores, "refresh_form": HistoryStoreForm( initial={ "store_id": self.toolbar.store_id, "exclude_history": True, } ), }, )
def test_history_sidebar(self): """Validate the history sidebar view.""" self.client.get("/json_view/") store_id = list(DebugToolbar._store.keys())[0] data = { "store_id": store_id, "hash": HistoryStoreForm.make_hash({"store_id": store_id}), } response = self.client.post(reverse("djdt:history_sidebar"), data=data) self.assertEqual(response.status_code, 200) self.assertEqual( set(response.json().keys()), { "VersionsPanel", "TimerPanel", "SettingsPanel", "HeadersPanel", "RequestPanel", "SQLPanel", "StaticFilesPanel", "TemplatesPanel", "CachePanel", "SignalsPanel", "LoggingPanel", "ProfilingPanel", }, )
def history_sidebar(request): """Returns the selected debug toolbar history snapshot.""" form = HistoryStoreForm(request.POST or None) if form.is_valid(): store_id = form.cleaned_data["store_id"] toolbar = DebugToolbar.fetch(store_id) context = {} for panel in toolbar.panels: if not panel.is_historical: continue panel_context = {"panel": panel} context[panel.panel_id] = { "button": render_to_string("debug_toolbar/includes/panel_button.html", panel_context), "content": render_to_string("debug_toolbar/includes/panel_content.html", panel_context), } return JsonResponse(context) return HttpResponseBadRequest("Form errors")