示例#1
0
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")
示例#2
0
def render_panel(request):
    """Render the contents of a panel"""
    toolbar = DebugToolbar.fetch(request.GET["store_id"])
    if toolbar is None:
        content = _("Data for this panel isn't available anymore. "
                    "Please reload the page and retry.")
        content = "<p>%s</p>" % escape(content)
    else:
        panel = toolbar.get_panel_by_id(request.GET["panel_id"])
        content = panel.content
    return HttpResponse(content)
def render_panel(request):
    """Render the contents of a panel"""
    toolbar = DebugToolbar.fetch(request.GET['storage_id'])
    if toolbar is None:
        content = _("Data for this panel isn't available anymore. "
                    "Please reload the page and retry.")
        content = "<p>%s</p>" % escape(content)
    else:
        panel = toolbar.get_panel_by_id(request.GET['panel_id'])
        content = panel.content()
    return HttpResponse(content)
示例#4
0
def render_panel(request):
    """Render the contents of a panel"""
    toolbar = DebugToolbar.fetch(int(request.GET['storage_id']))
    if toolbar is None:
        content = _("Data for this panel isn't available anymore. "
                    "Please reload the page and retry.")
        content = "<p>%s</p>" % escape(content)
    else:
        panel_id = request.GET['panel_id']
        for panel in toolbar.panels:
            if panel.dom_id() == panel_id:
                content = panel.content()
                break
    return HttpResponse(content)
示例#5
0
def render_panel(request):
    """Render the contents of a panel"""
    # Check if store_id key exist in GET request.
    if not request.GET.has_key("store_id"):
        content = _('"store_id" key is required')
        return HttpResponse(content)

    toolbar = DebugToolbar.fetch(request.GET["store_id"])
    if toolbar is None:
        content = _("Data for this panel isn't available anymore. " "Please reload the page and retry.")
        content = "<p>%s</p>" % escape(content)
    else:
        panel = toolbar.get_panel_by_id(request.GET["panel_id"])
        content = panel.content
    return HttpResponse(content)
示例#6
0
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")
    def __call__(self, request):
        DebugToolbar.store = self.store()
        response = super().__call__(request)
        DebugToolbar.store = _store

        content_type = response.get("Content-Type", "").split(";")[0]
        is_html = content_type in _HTML_TYPES
        is_graphiql = getattr(request, "_graphiql", False)

        if is_html and is_graphiql and response.status_code == 200:
            template = render_to_string("graphiql_debug_toolbar/base.html")
            response.write(template)
            set_content_length(response)

        if (is_html or self.store_id is None
                or not (is_graphiql and content_type == "application/json")):
            return response

        toolbar = DebugToolbar.fetch(self.store_id)
        payload = get_payload(request, response, toolbar)
        response.content = json.dumps(payload, cls=CallableJSONEncoder)
        set_content_length(response)
        return response