diff --git a/apps/amo/tests/test_middleware.py b/apps/amo/tests/test_middleware.py index 1b416ded66..7105fb9d70 100644 --- a/apps/amo/tests/test_middleware.py +++ b/apps/amo/tests/test_middleware.py @@ -109,3 +109,13 @@ class TestNoAddonsMiddleware(amo.tests.TestCase): self.assertRaises(http.Http404, self.process, 'some.addons') self.assertRaises(http.Http404, self.process, 'some.addons.thingy') assert not self.process('something.else') + + +class TestNoDjangoDebugToolbar(amo.tests.TestCase): + """Make sure the Django Debug Toolbar isn't available when DEBUG=False.""" + + def test_no_django_debug_toolbar(self): + with self.settings(DEBUG=False): + res = self.client.get(reverse('home'), follow=True) + assert 'djDebug' not in res.content + assert 'debug_toolbar' not in res.content diff --git a/docs/screenshots/django-debug-toolbar-expanded.png b/docs/screenshots/django-debug-toolbar-expanded.png new file mode 100644 index 0000000000..8566b8e0c0 Binary files /dev/null and b/docs/screenshots/django-debug-toolbar-expanded.png differ diff --git a/docs/screenshots/django-debug-toolbar.png b/docs/screenshots/django-debug-toolbar.png new file mode 100644 index 0000000000..2671765f7c Binary files /dev/null and b/docs/screenshots/django-debug-toolbar.png differ diff --git a/docs/topics/hacking/debugging.rst b/docs/topics/hacking/debugging.rst index 6f9328b740..6a45f1796a 100644 --- a/docs/topics/hacking/debugging.rst +++ b/docs/topics/hacking/debugging.rst @@ -46,5 +46,25 @@ All being well it should look like this: .. image:: /screenshots/docker-ipdb.png +Using the Django Debug Toolbar +------------------------------ + +The `Django Debug Toolbar`_ is very powerful and useful when viewing pages from +the website, to check the view used, its parameters, the SQL queries, the +templates rendered and their context... + +It should be enabled local development as long as ``settings.DEBUG`` is set to +``True`` (which it is by default). + +All being well it should look like this at the top-right of any web page on +olympia: + +.. image:: /screenshots/django-debug-toolbar.png + +If clicked, it looks like: + +.. image:: /screenshots/django-debug-toolbar-expanded.png + .. _ipdb: https://pypi.python.org/pypi/ipdb .. _docker-utils: https://pypi.python.org/pypi/docker-utils +.. _Django Debug Toolbar: http://django-debug-toolbar.readthedocs.org/en/1.3.2/index.html diff --git a/requirements/dev.txt b/requirements/dev.txt index 14da6ae850..cf11859b23 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -2,6 +2,6 @@ -r docs.txt -r flake8.txt -django-debug-toolbar==1.2 +django-debug-toolbar==1.3.2 django-fixture-magic==0.0.4 sqlparse==0.1.14 diff --git a/settings.py b/settings.py index 896445b8f3..49667b6020 100644 --- a/settings.py +++ b/settings.py @@ -79,6 +79,27 @@ TASK_USER_ID = 10968 # Set to True if we're allowed to use X-SENDFILE. XSENDFILE = False +# Enable the Django Debug Toolbar for local dev. +INSTALLED_APPS += ( + 'debug_toolbar', +) +DEBUG_TOOLBAR_PATCH_SETTINGS = False # Prevent DDT from patching the settings. + +MIDDLEWARE_CLASSES += ('debug_toolbar.middleware.DebugToolbarMiddleware',) + + +def show_toolbar_callback(request): + """Callback used by the Django Debug Toolbar to decide when to display.""" + # We want to make sure to have the DEBUG value at runtime, not the one we + # have in this specific settings file. + from django.conf import settings + return settings.DEBUG + + +DEBUG_TOOLBAR_CONFIG = { + "SHOW_TOOLBAR_CALLBACK": "settings.show_toolbar_callback", +} + # If you have settings you want to overload, put them in a local_settings.py. try: from local_settings import * # noqa