Skip to content

Commit

Permalink
Remove unmaintained django debug panel in favour of django debug tool…
Browse files Browse the repository at this point in the history
…bar.
  • Loading branch information
rtibbles committed Dec 18, 2024
1 parent a1e0333 commit 23ae14e
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 35 deletions.
12 changes: 6 additions & 6 deletions docs/manual_testing/general_notes/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,16 @@ Within the Chrome Dev Tools, navigate to the Network panel. Select a connection
For Kolibri, our target audience's network condition can be mimicked by setting connectivity to Regular 3G (100ms, 750kb/s, 250 kb/s).


Performance testing with Django Debug Panel
-------------------------------------------
Performance testing with Django Debug Toolbar
---------------------------------------------

We have built in support for Django Debug Panel (a Chrome extension that allows tracking of AJAX requests to Django).
We have built in support for Django Debug Toolbar, a Django application that provides a set of panels to display various debug information about the current request/response. It is particularly useful for performance testing.

To use this, ensure that you have development dependencies installed, and install the `Django Debug Panel Chrome Extension <https://chrome.google.com/webstore/detail/django-debug-panel/nbiajhhibgfgkjegbnflpdccejocmbbn>`__. You can then run the development or production servers with the following environment variable set::
To use this, ensure that you have development dependencies installed. You can then run the development or production servers with the following environment variable set::

DJANGO_SETTINGS_MODULE=kolibri.deployment.default.settings.debug_panel
DJANGO_SETTINGS_MODULE=kolibri.deployment.default.settings.debug_toolbar

This will activate the debug panel, and will display in the Dev tools panel of Chrome. This panel will track all page loads and API requests. However, all data bootstrapping into the template will be disabled, as our data bootstrapping prevents the page load request from being profiled, and also does not profile the bootstrapped API requests.
This will activate the debug toolbar, and will display in the HTML page of the site as an overlay. It is most useful when looking at individual API requests using the browsable API. The simplest way to see it for an API request is to go to that API request in the Network tab in the browser developer tools and open the URL in a new tab.


Generating user data
Expand Down
9 changes: 2 additions & 7 deletions kolibri/deployment/default/dev_urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.conf import settings
from django.http.response import HttpResponseRedirect
from django.urls import include
from django.urls import path
from django.urls import re_path
from drf_yasg import openapi
from drf_yasg.views import get_schema_view
Expand Down Expand Up @@ -48,10 +48,5 @@ def webpack_redirect_view(request):
name="schema-redoc",
),
re_path(r"^api-auth/", include("rest_framework.urls", namespace="rest_framework")),
path("__debug__/", include("debug_toolbar.urls")),
]

if getattr(settings, "DEBUG_PANEL_ACTIVE", False):

import debug_toolbar

urlpatterns = [re_path(r"^__debug__/", include(debug_toolbar.urls))] + urlpatterns
35 changes: 35 additions & 0 deletions kolibri/deployment/default/renderers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from rest_framework.renderers import BrowsableAPIRenderer


class LightBrowsableAPIRenderer(BrowsableAPIRenderer):
"""
Custom browsable API renderer that removes filtering and POST forms
for better performance with Django Debug Toolbar.
"""

def get_filter_form(self, data, view, request):
"""
Don't render the filter form.
"""
return None

def get_rendered_html_form(self, data, view, method, request):
"""
Don't render the HTML form.
"""
return None

def get_context(self, data, accepted_media_type, renderer_context):
"""
Modify context to remove unnecessary components.
"""
context = super().get_context(data, accepted_media_type, renderer_context)

# Remove form-related context
context["display_edit_forms"] = False
context["raw_data_post_form"] = None
context["raw_data_put_form"] = None
context["raw_data_patch_form"] = None
context["raw_data_put_or_patch_form"] = None

return context
18 changes: 0 additions & 18 deletions kolibri/deployment/default/settings/debug_panel.py

This file was deleted.

12 changes: 12 additions & 0 deletions kolibri/deployment/default/settings/debug_toolbar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from .dev import * # noqa

INTERNAL_IPS = ["127.0.0.1"]

INSTALLED_APPS += ["debug_toolbar"] # noqa

MIDDLEWARE += ["debug_toolbar.middleware.DebugToolbarMiddleware"] # noqa

CACHES["default"]["TIMEOUT"] = 0 # noqa

if "process_cache" in CACHES: # noqa
CACHES["process_cache"]["TIMEOUT"] = 0 # noqa
2 changes: 1 addition & 1 deletion kolibri/deployment/default/settings/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
],
"DEFAULT_RENDERER_CLASSES": (
"rest_framework.renderers.JSONRenderer",
"rest_framework.renderers.BrowsableAPIRenderer",
"kolibri.deployment.default.renderers.LightBrowsableAPIRenderer",
),
"EXCEPTION_HANDLER": "kolibri.core.utils.exception_handler.custom_exception_handler",
}
Expand Down
4 changes: 1 addition & 3 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ flake8==3.8.3
flake8-print==5.0.0
pre-commit==3.8.0
tox==3.1.3
django-debug-panel==0.8.3
django-debug-toolbar==1.9.1
ruamel.yaml.clib==0.2.2; python_version < "3"
django-debug-toolbar==4.3.0
drf-yasg==1.21.7
coreapi==2.3.3
nodeenv==1.3.3
Expand Down

0 comments on commit 23ae14e

Please sign in to comment.