views.py 877 B

12345678910111213141516171819202122232425
  1. from django.http import JsonResponse
  2. from django.utils.html import escape
  3. from django.utils.translation import gettext as _
  4. from debug_toolbar.decorators import render_with_toolbar_language, require_show_toolbar
  5. from debug_toolbar.toolbar import DebugToolbar
  6. @require_show_toolbar
  7. @render_with_toolbar_language
  8. def render_panel(request):
  9. """Render the contents of a panel"""
  10. toolbar = DebugToolbar.fetch(request.GET["store_id"])
  11. if toolbar is None:
  12. content = _(
  13. "Data for this panel isn't available anymore. "
  14. "Please reload the page and retry."
  15. )
  16. content = "<p>%s</p>" % escape(content)
  17. scripts = []
  18. else:
  19. panel = toolbar.get_panel_by_id(request.GET["panel_id"])
  20. content = panel.content
  21. scripts = panel.scripts
  22. return JsonResponse({"content": content, "scripts": scripts})