[Python-modules-commits] [python-django-debug-toolbar] 01/05: Imported Upstream version 1.4

Andrew Starr-Bochicchio asb at moszumanska.debian.org
Sun Nov 1 21:55:31 UTC 2015


This is an automated email from the git hooks/post-receive script.

asb pushed a commit to branch master
in repository python-django-debug-toolbar.

commit 1ecc7203e7f3e2351ae512b6431e22ce55f86437
Author: Andrew Starr-Bochicchio <a.starr.b at gmail.com>
Date:   Sun Nov 1 16:42:05 2015 -0500

    Imported Upstream version 1.4
---
 .travis.yml                                        |  21 +-
 Makefile                                           |  18 +-
 README.rst                                         |   5 +-
 debug_toolbar/__init__.py                          |   1 -
 debug_toolbar/apps.py                              |   1 +
 debug_toolbar/compat.py                            |  65 ++++++
 debug_toolbar/locale/en/LC_MESSAGES/django.po      | 217 +++++++++++----------
 debug_toolbar/management/commands/debugsqlshell.py |  14 +-
 debug_toolbar/middleware.py                        |  24 ++-
 debug_toolbar/models.py                            |   9 -
 debug_toolbar/panels/__init__.py                   |  32 ++-
 debug_toolbar/panels/cache.py                      |  86 ++++----
 debug_toolbar/panels/headers.py                    |   9 +-
 debug_toolbar/panels/logging.py                    |  12 +-
 debug_toolbar/panels/profiling.py                  |  41 ++--
 debug_toolbar/panels/redirects.py                  |   8 +-
 debug_toolbar/panels/request.py                    |   2 +-
 debug_toolbar/panels/settings.py                   |  10 +-
 debug_toolbar/panels/signals.py                    |  23 ++-
 debug_toolbar/panels/sql/__init__.py               |   2 +-
 debug_toolbar/panels/sql/forms.py                  |   4 +-
 debug_toolbar/panels/sql/panel.py                  |  50 ++++-
 debug_toolbar/panels/sql/tracking.py               |  21 +-
 debug_toolbar/panels/sql/utils.py                  |   3 +-
 debug_toolbar/panels/staticfiles.py                |  24 ++-
 debug_toolbar/panels/templates/__init__.py         |   2 +-
 debug_toolbar/panels/templates/panel.py            | 121 +++++++-----
 debug_toolbar/panels/templates/views.py            |  22 ++-
 debug_toolbar/panels/timer.py                      |  13 +-
 debug_toolbar/panels/versions.py                   |  26 +--
 debug_toolbar/settings.py                          |  53 +++--
 debug_toolbar/static/debug_toolbar/css/print.css   |   3 +
 debug_toolbar/static/debug_toolbar/css/toolbar.css | 109 ++++++-----
 .../static/debug_toolbar/js/jquery_existing.js     |   1 +
 .../static/debug_toolbar/js/jquery_post.js         |   1 +
 .../static/debug_toolbar/js/jquery_pre.js          |   1 +
 debug_toolbar/static/debug_toolbar/js/toolbar.js   |  71 ++++---
 .../static/debug_toolbar/js/toolbar.profiling.js   |   1 +
 .../static/debug_toolbar/js/toolbar.sql.js         |   3 +
 .../static/debug_toolbar/js/toolbar.timer.js       |   7 +-
 debug_toolbar/templates/debug_toolbar/base.html    |  32 ++-
 .../templates/debug_toolbar/panels/cache.html      |   8 +-
 .../templates/debug_toolbar/panels/headers.html    |   2 +-
 .../templates/debug_toolbar/panels/logging.html    |   2 +-
 .../templates/debug_toolbar/panels/profiling.html  |   7 +-
 .../templates/debug_toolbar/panels/request.html    |  12 +-
 .../templates/debug_toolbar/panels/settings.html   |   2 +-
 .../templates/debug_toolbar/panels/signals.html    |   2 +-
 .../templates/debug_toolbar/panels/sql.html        |  39 ++--
 .../debug_toolbar/panels/sql_explain.html          |   6 +-
 .../debug_toolbar/panels/sql_profile.html          |   6 +-
 .../templates/debug_toolbar/panels/sql_select.html |   6 +-
 .../debug_toolbar/panels/staticfiles.html          |   3 +-
 .../debug_toolbar/panels/template_source.html      |   4 +-
 .../templates/debug_toolbar/panels/templates.html  |   6 +-
 .../templates/debug_toolbar/panels/timer.html      |  14 +-
 .../templates/debug_toolbar/panels/versions.html   |   2 +-
 debug_toolbar/templatetags/__init__.py             |   0
 debug_toolbar/templatetags/debug_toolbar_compat.py |  13 ++
 debug_toolbar/toolbar.py                           |  34 ++--
 debug_toolbar/utils.py                             |  57 ++++--
 docs/changes.rst                                   |  42 ++++
 docs/conf.py                                       |   8 +-
 docs/configuration.rst                             |   8 +-
 docs/contributing.rst                              |   8 +-
 docs/installation.rst                              |  13 +-
 docs/panels.rst                                    |  97 ++++++++-
 docs/tips.rst                                      |  16 +-
 example/README.rst                                 |   6 +-
 example/django-debug-toolbar.png                   | Bin 417544 -> 170704 bytes
 example/settings.py                                |   9 +
 example/urls.py                                    |  18 +-
 example/wsgi.py                                    |   4 +-
 requirements_dev.txt                               |   2 +-
 setup.cfg                                          |   8 +
 setup.py                                           |  11 +-
 tests/__init__.py                                  |   6 +-
 tests/base.py                                      |   2 +-
 tests/commands/test_debugsqlshell.py               |  11 +-
 tests/loaders.py                                   |  17 ++
 tests/panels/test_cache.py                         |  25 ++-
 tests/panels/test_logging.py                       |  25 ++-
 tests/panels/test_profiling.py                     |  23 ++-
 tests/panels/test_redirects.py                     |  33 +++-
 tests/panels/test_request.py                       |  15 ++
 tests/panels/test_sql.py                           |  50 ++++-
 tests/panels/test_staticfiles.py                   |  16 ++
 tests/panels/test_template.py                      |  30 ++-
 tests/settings.py                                  |  11 +-
 tests/templates/{basic.html => base.html}          |   1 +
 tests/templates/basic.html                         |  10 +-
 tests/test_integration.py                          |  60 ++++--
 tests/test_utils.py                                |   4 +-
 tests/urls.py                                      |  26 ++-
 tests/views.py                                     |   6 +
 tox.ini                                            | 124 +++---------
 96 files changed, 1346 insertions(+), 792 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 51f9ede..f0c01f2 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,23 +1,26 @@
 language: python
+sudo: false
 python:
-  - "2.6"
   - "2.7"
   - "3.2"
   - "3.3"
   - "3.4"
+  - "3.5"
 env:
-  - DJANGO_VERSION=1.4.10
-  - DJANGO_VERSION=1.5.5
-  - DJANGO_VERSION=1.6.1
+  - DJANGO="Django>=1.7.0,<1.8.0"
+  - DJANGO="Django>=1.8.0,<1.9.0"
+  - DJANGO="https://www.djangoproject.com/download/1.9a1/tarball/"
 matrix:
   exclude:
     - python: "3.2"
-      env: DJANGO_VERSION=1.4.10
+      env: DJANGO="https://www.djangoproject.com/download/1.9a1/tarball/"
     - python: "3.3"
-      env: DJANGO_VERSION=1.4.10
-    - python: "3.4"
-      env: DJANGO_VERSION=1.4.10
+      env: DJANGO="https://www.djangoproject.com/download/1.9a1/tarball/"
+    - python: "3.5"
+      env: DJANGO="Django>=1.7.0,<1.8.0"
+    - python: "3.5"
+      env: DJANGO="Django>=1.8.0,<1.9.0"
 install:
   - pip install -e .
-  - pip install Django==$DJANGO_VERSION django-discover-runner sqlparse
+  - travis_retry pip install $DJANGO django-discover-runner sqlparse
 script: make test
diff --git a/Makefile b/Makefile
index f02d9af..30aa2cd 100644
--- a/Makefile
+++ b/Makefile
@@ -3,28 +3,34 @@
 flake8:
 	flake8 debug_toolbar example tests
 
+isort:
+	isort -rc debug_toolbar example tests
+
+isort_check_only:
+	isort -rc -c debug_toolbar example tests
+
 example:
 	DJANGO_SETTINGS_MODULE=example.settings \
-		django-admin.py runserver
+		django-admin runserver
 
 test:
 	DJANGO_SETTINGS_MODULE=tests.settings \
-		django-admin.py test tests
+		django-admin test tests
 
 test_selenium:
 	DJANGO_SELENIUM_TESTS=true DJANGO_SETTINGS_MODULE=tests.settings \
-		django-admin.py test tests
+		django-admin test tests
 
 coverage:
 	coverage erase
 	DJANGO_SETTINGS_MODULE=tests.settings \
-		coverage run --branch --source=debug_toolbar `which django-admin.py` test tests
+		coverage run --branch --source=debug_toolbar `which django-admin` test tests
 	coverage html
 
 translatable_strings:
-	cd debug_toolbar && django-admin.py makemessages -l en --no-obsolete
+	cd debug_toolbar && django-admin makemessages -l en --no-obsolete
 	@echo "Please commit changes and run 'tx push -s' (or wait for Transifex to pick them)"
 
 update_translations:
 	tx pull -a --minimum-perc=10
-	cd debug_toolbar && django-admin.py compilemessages
+	cd debug_toolbar && django-admin compilemessages
diff --git a/README.rst b/README.rst
index 215f424..5332b8c 100644
--- a/README.rst
+++ b/README.rst
@@ -19,10 +19,7 @@ Here's a screenshot of the toolbar in action:
 In addition to the built-in panels, a number of third-party panels are
 contributed by the community.
 
-The current version of the Debug Toolbar is 1.2.1. It works on Django 1.4 to 1.7.
-
-If you're using Django 1.4, you will need Django ≥ 1.4.2 and Python ≥ 2.6.5.
-If you're using Django ≥ 1.5, there aren't any restrictions.
+The current version of the Debug Toolbar is 1.4. It works on Django ≥ 1.7.
 
 Documentation, including installation and configuration instructions, is
 available at http://django-debug-toolbar.readthedocs.org/.
diff --git a/debug_toolbar/__init__.py b/debug_toolbar/__init__.py
index be51a7e..0d45138 100644
--- a/debug_toolbar/__init__.py
+++ b/debug_toolbar/__init__.py
@@ -1,6 +1,5 @@
 from __future__ import absolute_import, unicode_literals
 
-
 __all__ = ['VERSION']
 
 
diff --git a/debug_toolbar/apps.py b/debug_toolbar/apps.py
index 17f8dad..1894a40 100644
--- a/debug_toolbar/apps.py
+++ b/debug_toolbar/apps.py
@@ -13,3 +13,4 @@ class DebugToolbarConfig(AppConfig):
     def ready(self):
         if dt_settings.PATCH_SETTINGS:
             dt_settings.patch_all()
+        dt_settings.check_middleware()
diff --git a/debug_toolbar/compat.py b/debug_toolbar/compat.py
new file mode 100644
index 0000000..a38232c
--- /dev/null
+++ b/debug_toolbar/compat.py
@@ -0,0 +1,65 @@
+"""
+This file exists to contain all Django and Python compatibility issues.
+
+In order to avoid circular references, nothing should be imported from
+debug_toolbar.
+"""
+
+from django.conf import settings
+from django.core.exceptions import ImproperlyConfigured
+
+try:
+    from django.template.base import linebreak_iter  # NOQA
+except ImportError:  # Django < 1.9
+    from django.views.debug import linebreak_iter  # NOQA
+
+try:
+    from django.template.engine import Engine
+except ImportError:  # Django < 1.8
+    Engine = None
+    from django.template.context import get_standard_processors  # NOQA
+    from django.template.loader import find_template_loader  # NOQA
+
+
+def get_template_dirs():
+    """Compatibility method to fetch the template directories."""
+    if Engine:
+        try:
+            engine = Engine.get_default()
+        except ImproperlyConfigured:
+            template_dirs = []
+        else:
+            template_dirs = engine.dirs
+    else:  # Django < 1.8
+        template_dirs = settings.TEMPLATE_DIRS
+    return template_dirs
+
+
+def get_template_loaders():
+    """Compatibility method to fetch the template loaders."""
+    if Engine:
+        try:
+            engine = Engine.get_default()
+        except ImproperlyConfigured:
+            loaders = []
+        else:
+            loaders = engine.template_loaders
+    else:  # Django < 1.8
+        loaders = [
+            find_template_loader(loader_name)
+            for loader_name in settings.TEMPLATE_LOADERS]
+    return loaders
+
+
+def get_template_context_processors():
+    """Compatibility method to fetch the template context processors."""
+    if Engine:
+        try:
+            engine = Engine.get_default()
+        except ImproperlyConfigured:
+            context_processors = []
+        else:
+            context_processors = engine.template_context_processors
+    else:  # Django < 1.8
+        context_processors = get_standard_processors()
+    return context_processors
diff --git a/debug_toolbar/locale/en/LC_MESSAGES/django.po b/debug_toolbar/locale/en/LC_MESSAGES/django.po
index 0465d4a..69e0d02 100644
--- a/debug_toolbar/locale/en/LC_MESSAGES/django.po
+++ b/debug_toolbar/locale/en/LC_MESSAGES/django.po
@@ -6,7 +6,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: Django Debug Toolbar\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2014-04-25 21:52+0200\n"
+"POT-Creation-Date: 2015-07-06 16:50-0400\n"
 "PO-Revision-Date: 2012-03-31 20:10+0000\n"
 "Last-Translator: \n"
 "Language-Team: \n"
@@ -20,46 +20,40 @@ msgstr ""
 msgid "Debug Toolbar"
 msgstr ""
 
-#: views.py:14
-msgid ""
-"Data for this panel isn't available anymore. Please reload the page and "
-"retry."
-msgstr ""
-
-#: panels/cache.py:191
+#: panels/cache.py:209
 msgid "Cache"
 msgstr ""
 
-#: panels/cache.py:196
+#: panels/cache.py:214
 #, python-format
 msgid "%(cache_calls)d call in %(time).2fms"
 msgid_plural "%(cache_calls)d calls in %(time).2fms"
 msgstr[0] ""
 msgstr[1] ""
 
-#: panels/cache.py:204
+#: panels/cache.py:222
 #, python-format
 msgid "Cache calls from %(count)d backend"
 msgid_plural "Cache calls from %(count)d backends"
 msgstr[0] ""
 msgstr[1] ""
 
-#: panels/headers.py:35
+#: panels/headers.py:33
 msgid "Headers"
 msgstr ""
 
-#: panels/logging.py:64
+#: panels/logging.py:63
 msgid "Logging"
 msgstr ""
 
-#: panels/logging.py:70
+#: panels/logging.py:69
 #, python-format
 msgid "%(count)s message"
 msgid_plural "%(count)s messages"
 msgstr[0] ""
 msgstr[1] ""
 
-#: panels/logging.py:73
+#: panels/logging.py:72
 msgid "Log messages"
 msgstr ""
 
@@ -83,49 +77,106 @@ msgstr ""
 msgid "<unavailable>"
 msgstr ""
 
-#: panels/settings.py:20
+#: panels/settings.py:17
 msgid "Settings"
 msgstr ""
 
-#: panels/settings.py:23
+#: panels/settings.py:20
 #, python-format
 msgid "Settings from <code>%s</code>"
 msgstr ""
 
-#: panels/signals.py:45
+#: panels/signals.py:42
 #, python-format
 msgid "%(num_receivers)d receiver of 1 signal"
 msgid_plural "%(num_receivers)d receivers of 1 signal"
 msgstr[0] ""
 msgstr[1] ""
 
-#: panels/signals.py:48
+#: panels/signals.py:45
 #, python-format
 msgid "%(num_receivers)d receiver of %(num_signals)d signals"
 msgid_plural "%(num_receivers)d receivers of %(num_signals)d signals"
 msgstr[0] ""
 msgstr[1] ""
 
-#: panels/signals.py:53
+#: panels/signals.py:50
 msgid "Signals"
 msgstr ""
 
-#: panels/staticfiles.py:89
+#: panels/sql/panel.py:23
+msgid "Autocommit"
+msgstr ""
+
+#: panels/sql/panel.py:24
+msgid "Read uncommitted"
+msgstr ""
+
+#: panels/sql/panel.py:25
+msgid "Read committed"
+msgstr ""
+
+#: panels/sql/panel.py:26
+msgid "Repeatable read"
+msgstr ""
+
+#: panels/sql/panel.py:27
+msgid "Serializable"
+msgstr ""
+
+#: panels/sql/panel.py:38
+msgid "Idle"
+msgstr ""
+
+#: panels/sql/panel.py:39
+msgid "Active"
+msgstr ""
+
+#: panels/sql/panel.py:40
+msgid "In transaction"
+msgstr ""
+
+#: panels/sql/panel.py:41
+msgid "In error"
+msgstr ""
+
+#: panels/sql/panel.py:42
+msgid "Unknown"
+msgstr ""
+
+#: panels/sql/panel.py:106
+msgid "SQL"
+msgstr ""
+
+#: panels/staticfiles.py:86
 #, python-format
 msgid "Static files (%(num_found)s found, %(num_used)s used)"
 msgstr ""
 
-#: panels/staticfiles.py:107
+#: panels/staticfiles.py:104
 msgid "Static files"
 msgstr ""
 
-#: panels/staticfiles.py:112
+#: panels/staticfiles.py:109
 #, python-format
 msgid "%(num_used)s file used"
 msgid_plural "%(num_used)s files used"
 msgstr[0] ""
 msgstr[1] ""
 
+#: panels/templates/panel.py:171
+msgid "Templates"
+msgstr ""
+
+#: panels/templates/panel.py:176
+#, python-format
+msgid "Templates (%(num_templates)s rendered)"
+msgstr ""
+
+#: panels/templates/panel.py:207
+msgid "No origin"
+msgstr ""
+
 #: panels/timer.py:23
 #, python-format
 msgid "CPU: %(cum)0.2fms (%(total)0.2fms)"
@@ -188,63 +239,10 @@ msgstr ""
 msgid "%(vcsw)d voluntary, %(ivcsw)d involuntary"
 msgstr ""
 
-#: panels/versions.py:25
+#: panels/versions.py:21
 msgid "Versions"
 msgstr ""
 
-#: panels/sql/panel.py:22
-msgid "Autocommit"
-msgstr ""
-
-#: panels/sql/panel.py:23
-msgid "Read uncommitted"
-msgstr ""
-
-#: panels/sql/panel.py:24
-msgid "Read committed"
-msgstr ""
-
-#: panels/sql/panel.py:25
-msgid "Repeatable read"
-msgstr ""
-
-#: panels/sql/panel.py:26
-msgid "Serializable"
-msgstr ""
-
-#: panels/sql/panel.py:37
-msgid "Idle"
-msgstr ""
-
-#: panels/sql/panel.py:38
-msgid "Active"
-msgstr ""
-
-#: panels/sql/panel.py:39
-msgid "In transaction"
-msgstr ""
-
-#: panels/sql/panel.py:40
-msgid "In error"
-msgstr ""
-
-#: panels/sql/panel.py:41
-msgid "Unknown"
-msgstr ""
-
-#: panels/sql/panel.py:105
-msgid "SQL"
-msgstr ""
-
-#: panels/templates/panel.py:141
-msgid "Templates"
-msgstr ""
-
-#: panels/templates/panel.py:146
-#, python-format
-msgid "Templates (%(num_templates)s rendered)"
-msgstr ""
-
 #: templates/debug_toolbar/base.html:19
 msgid "Hide toolbar"
 msgstr ""
@@ -265,21 +263,6 @@ msgstr ""
 msgid "Show toolbar"
 msgstr ""
 
-#: templates/debug_toolbar/base.html:53
-msgid "Close"
-msgstr ""
-
-#: templates/debug_toolbar/redirect.html:8
-msgid "Location:"
-msgstr ""
-
-#: templates/debug_toolbar/redirect.html:10
-msgid ""
-"The Django Debug Toolbar has intercepted a redirect to the above URL for "
-"debug viewing purposes. You can click the above link to continue with the "
-"redirect as normal."
-msgstr ""
-
 #: templates/debug_toolbar/panels/cache.html:2
 msgid "Summary"
 msgstr ""
@@ -309,7 +292,7 @@ msgid "Calls"
 msgstr ""
 
 #: templates/debug_toolbar/panels/cache.html:43
-#: templates/debug_toolbar/panels/sql.html:20
+#: templates/debug_toolbar/panels/sql.html:23
 msgid "Time (ms)"
 msgstr ""
 
@@ -483,46 +466,49 @@ msgid_plural "%(num)s queries"
 msgstr[0] ""
 msgstr[1] ""
 
-#: templates/debug_toolbar/panels/sql.html:18
+#: templates/debug_toolbar/panels/sql.html:9
+#, python-format
+msgid "including %(dupes)s duplicates"
+msgstr ""
+
+#: templates/debug_toolbar/panels/sql.html:21
 msgid "Query"
 msgstr ""
 
-#: templates/debug_toolbar/panels/sql.html:19
+#: templates/debug_toolbar/panels/sql.html:22
 #: templates/debug_toolbar/panels/timer.html:36
 msgid "Timeline"
 msgstr ""
 
-#: templates/debug_toolbar/panels/sql.html:21
+#: templates/debug_toolbar/panels/sql.html:24
 msgid "Action"
 msgstr ""
 
-#: templates/debug_toolbar/panels/sql.html:64
+#: templates/debug_toolbar/panels/sql.html:39
+#, python-format
+msgid "Duplicated %(dupes)s times."
+msgstr ""
+
+#: templates/debug_toolbar/panels/sql.html:71
 msgid "Connection:"
 msgstr ""
 
-#: templates/debug_toolbar/panels/sql.html:66
+#: templates/debug_toolbar/panels/sql.html:73
 msgid "Isolation level:"
 msgstr ""
 
-#: templates/debug_toolbar/panels/sql.html:69
+#: templates/debug_toolbar/panels/sql.html:76
 msgid "Transaction status:"
 msgstr ""
 
-#: templates/debug_toolbar/panels/sql.html:83
+#: templates/debug_toolbar/panels/sql.html:90
 msgid "(unknown)"
 msgstr ""
 
-#: templates/debug_toolbar/panels/sql.html:92
+#: templates/debug_toolbar/panels/sql.html:99
 msgid "No SQL queries were recorded during this request."
 msgstr ""
 
-#: templates/debug_toolbar/panels/sql_explain.html:3
-#: templates/debug_toolbar/panels/sql_profile.html:3
-#: templates/debug_toolbar/panels/sql_select.html:3
-#: templates/debug_toolbar/panels/template_source.html:3
-msgid "Back"
-msgstr ""
-
 #: templates/debug_toolbar/panels/sql_explain.html:4
 msgid "SQL explained"
 msgstr ""
@@ -652,3 +638,20 @@ msgstr ""
 #: templates/debug_toolbar/panels/versions.html:6
 msgid "Version"
 msgstr ""
+
+#: templates/debug_toolbar/redirect.html:8
+msgid "Location:"
+msgstr ""
+
+#: templates/debug_toolbar/redirect.html:10
+msgid ""
+"The Django Debug Toolbar has intercepted a redirect to the above URL for "
+"debug viewing purposes. You can click the above link to continue with the "
+"redirect as normal."
+msgstr ""
+
+#: views.py:14
+msgid ""
+"Data for this panel isn't available anymore. Please reload the page and "
+"retry."
+msgstr ""
diff --git a/debug_toolbar/management/commands/debugsqlshell.py b/debug_toolbar/management/commands/debugsqlshell.py
index 7e1471f..2bb2b8d 100644
--- a/debug_toolbar/management/commands/debugsqlshell.py
+++ b/debug_toolbar/management/commands/debugsqlshell.py
@@ -2,17 +2,13 @@ from __future__ import absolute_import, print_function, unicode_literals
 
 from time import time
 
-# 'debugsqlshell' is the same as the 'shell'.
-from django.core.management.commands.shell import Command               # noqa
-try:
-    from django.db.backends import utils
-except ImportError:
-    from django.db.backends import util as utils
-
 import sqlparse
+# 'debugsqlshell' is the same as the 'shell'.
+from django.core.management.commands.shell import Command  # noqa
+from django.db.backends import utils as db_backends_utils
 
 
-class PrintQueryWrapper(utils.CursorDebugWrapper):
+class PrintQueryWrapper(db_backends_utils.CursorDebugWrapper):
     def execute(self, sql, params=()):
         start_time = time()
         try:
@@ -25,4 +21,4 @@ class PrintQueryWrapper(utils.CursorDebugWrapper):
             print('%s [%.2fms]' % (formatted_sql, duration))
 
 
-utils.CursorDebugWrapper = PrintQueryWrapper
+db_backends_utils.CursorDebugWrapper = PrintQueryWrapper
diff --git a/debug_toolbar/middleware.py b/debug_toolbar/middleware.py
index 7f83ccb..dfd7179 100644
--- a/debug_toolbar/middleware.py
+++ b/debug_toolbar/middleware.py
@@ -8,11 +8,12 @@ import re
 import threading
 
 from django.conf import settings
+from django.utils import six
 from django.utils.encoding import force_text
-from django.utils.importlib import import_module
+from django.utils.module_loading import import_string
 
-from debug_toolbar.toolbar import DebugToolbar
 from debug_toolbar import settings as dt_settings
+from debug_toolbar.toolbar import DebugToolbar
 
 _HTML_TYPES = ('text/html', 'application/xhtml+xml')
 # Handles python threading module bug - http://bugs.python.org/issue14308
@@ -39,13 +40,18 @@ class DebugToolbarMiddleware(object):
     """
     debug_toolbars = {}
 
+    def __init__(self):
+        # If SHOW_TOOLBAR_CALLBACK is a string, which is the recommended
+        # setup, resolve it to the corresponding callable.
+        func_or_path = dt_settings.CONFIG['SHOW_TOOLBAR_CALLBACK']
+        if isinstance(func_or_path, six.string_types):
+            self.show_toolbar = import_string(func_or_path)
+        else:
+            self.show_toolbar = func_or_path
+
     def process_request(self, request):
         # Decide whether the toolbar is active for this request.
-        func_path = dt_settings.CONFIG['SHOW_TOOLBAR_CALLBACK']
-        # Replace this with import_by_path in Django >= 1.6.
-        mod_path, func_name = func_path.rsplit('.', 1)
-        show_toolbar = getattr(import_module(mod_path), func_name)
-        if not show_toolbar(request):
+        if not self.show_toolbar(request):
             return
 
         toolbar = DebugToolbar(request)
@@ -118,6 +124,10 @@ class DebugToolbarMiddleware(object):
             # When the body ends with a newline, there's two trailing groups.
             bits.append(''.join(m[0] for m in matches if m[1] == ''))
         if len(bits) > 1:
+            # When the toolbar will be inserted for sure, generate the stats.
+            for panel in reversed(toolbar.enabled_panels):
+                panel.generate_stats(request, response)
+
             bits[-2] += toolbar.render_toolbar()
             response.content = insert_before.join(bits)
             if response.get('Content-Length', None):
diff --git a/debug_toolbar/models.py b/debug_toolbar/models.py
deleted file mode 100644
index 1874748..0000000
--- a/debug_toolbar/models.py
+++ /dev/null
@@ -1,9 +0,0 @@
-from __future__ import absolute_import, unicode_literals
-
-import django
-
-from debug_toolbar import settings as dt_settings
-
-
-if dt_settings.PATCH_SETTINGS and django.VERSION[:2] < (1, 7):
-    dt_settings.patch_all()
diff --git a/debug_toolbar/panels/__init__.py b/debug_toolbar/panels/__init__.py
index 74b0734..bf1f633 100644
--- a/debug_toolbar/panels/__init__.py
+++ b/debug_toolbar/panels/__init__.py
@@ -24,7 +24,16 @@ class Panel(object):
     @property
     def enabled(self):
         # Check to see if settings has a default value for it
-        if get_name_from_obj(self) in dt_settings.CONFIG['DISABLE_PANELS']:
+        disabled_panels = dt_settings.CONFIG['DISABLE_PANELS']
+        panel_path = get_name_from_obj(self)
+        # Some panels such as the SQLPanel and TemplatesPanel exist in a
+        # panel module, but can be disabled without panel in the path.
+        # For that reason, replace .panel. in the path and check for that
+        # value in the disabled panels as well.
+        disable_panel = (
+            panel_path in disabled_panels or
+            panel_path.replace('.panel.', '.') in disabled_panels)
+        if disable_panel:
             default = 'off'
         else:
             default = 'on'
@@ -158,10 +167,29 @@ class Panel(object):
 
     def process_response(self, request, response):
         """
-        Like process_response in Django's middleware.
+        Like process_response in Django's middleware. This is similar to
+        :meth:`generate_stats <debug_toolbar.panels.Panel.generate_stats>`,
+        but will be executed on every request. It should be used when either
+        the logic needs to be executed on every request or it needs to change
+        the response entirely, such as :class:`RedirectsPanel`.
 
         Write panel logic related to the response there. Post-process data
         gathered while the view executed. Save data with :meth:`record_stats`.
+
+        Return a response to overwrite the existing response.
+        """
+
+    def generate_stats(self, request, response):
+        """
+        Similar to :meth:`process_response
+        <debug_toolbar.panels.Panel.process_response>`,
+        but may not be executed on every request. This will only be called if
+        the toolbar will be inserted into the request.
+
+        Write panel logic related to the response there. Post-process data
+        gathered while the view executed. Save data with :meth:`record_stats`.
+
+        Does not return a value.
         """
 
 
diff --git a/debug_toolbar/panels/cache.py b/debug_toolbar/panels/cache.py
index f2db329..1b9d881 100644
--- a/debug_toolbar/panels/cache.py
+++ b/debug_toolbar/panels/cache.py
@@ -3,24 +3,25 @@ from __future__ import absolute_import, unicode_literals
 import inspect
 import sys
 import time
+from collections import OrderedDict
 
+import django
 from django.conf import settings
 from django.core import cache
-from django.core.cache import cache as original_cache, get_cache as original_get_cache
+from django.core.cache import CacheHandler, caches as original_caches
 from django.core.cache.backends.base import BaseCache
 from django.dispatch import Signal
-from django.template import Node
+from django.middleware import cache as middleware_cache
 from django.utils.translation import ugettext_lazy as _, ungettext
-try:
-    from collections import OrderedDict
-except ImportError:
-    from django.utils.datastructures import SortedDict as OrderedDict
 
-from debug_toolbar.panels import Panel
-from debug_toolbar.utils import (tidy_stacktrace, render_stacktrace,
-                                 get_template_info, get_stack)
 from debug_toolbar import settings as dt_settings
+from debug_toolbar.panels import Panel
+from debug_toolbar.utils import (
+    get_stack, get_template_info, render_stacktrace, tidy_stacktrace,
+)
 
+if django.VERSION[:2] < (1, 9):
+    from django.core.cache import get_cache as original_get_cache
 
 cache_called = Signal(providing_args=[
     "time_taken", "name", "return_value", "args", "kwargs", "trace"])
@@ -37,19 +38,7 @@ def send_signal(method):
         else:
             stacktrace = []
 
-        template_info = None
-        cur_frame = sys._getframe().f_back
-        try:
-            while cur_frame is not None:
-                if cur_frame.f_code.co_name == 'render':
-                    node = cur_frame.f_locals['self']
-                    if isinstance(node, Node):
-                        template_info = get_template_info(node.source)
-                        break
-                cur_frame = cur_frame.f_back
-        except Exception:
-            pass
-        del cur_frame
+        template_info = get_template_info()
         cache_called.send(sender=self.__class__, time_taken=t,
                           name=method.__name__, return_value=value,
                           args=args, kwargs=kwargs, trace=stacktrace,
@@ -94,8 +83,14 @@ class CacheStatTracker(BaseCache):
         return self.cache.delete(*args, **kwargs)
 
     @send_signal
+    def clear(self, *args, **kwargs):
+        return self.cache.clear(*args, **kwargs)
+
+    @send_signal
     def has_key(self, *args, **kwargs):
-        return self.cache.has_key(*args, **kwargs)
+        # Ignore flake8 rules for has_key since we need to support caches
+        # that may be using has_key.
+        return self.cache.has_key(*args, **kwargs)  # noqa
 
     @send_signal
     def incr(self, *args, **kwargs):
@@ -126,8 +121,25 @@ class CacheStatTracker(BaseCache):
         return self.cache.decr_version(*args, **kwargs)
 
 
-def get_cache(*args, **kwargs):
-    return CacheStatTracker(original_get_cache(*args, **kwargs))
+if django.VERSION[:2] < (1, 9):
+    def get_cache(*args, **kwargs):
+        return CacheStatTracker(original_get_cache(*args, **kwargs))
+
+
+class CacheHandlerPatch(CacheHandler):
+    def __getitem__(self, alias):
+        actual_cache = super(CacheHandlerPatch, self).__getitem__(alias)
+        return CacheStatTracker(actual_cache)
+
+
+# Must monkey patch the middleware's cache module as well in order to
+# cover per-view level caching. This needs to be monkey patched outside
+# of the enable_instrumentation method since the django's
+# decorator_from_middleware_with_args will store the cache from core.caches
+# when it wraps the view.
+if django.VERSION[:2] < (1, 9):
+    middleware_cache.get_cache = get_cache
+middleware_cache.caches = CacheHandlerPatch()
 
 
 class CachePanel(Panel):
@@ -147,6 +159,7 @@ class CachePanel(Panel):
             ('get', 0),
             ('set', 0),
             ('delete', 0),
+            ('clear', 0),
             ('get_many', 0),
             ('set_many', 0),
             ('delete_many', 0),
@@ -206,16 +219,23 @@ class CachePanel(Panel):
                          count) % dict(count=count)
 
     def enable_instrumentation(self):
-        # This isn't thread-safe because cache connections aren't thread-local
-        # in Django, unlike database connections.
-        cache.cache = CacheStatTracker(original_cache)
-        cache.get_cache = get_cache
+        if django.VERSION[:2] < (1, 9):
+            cache.get_cache = get_cache
+        if isinstance(middleware_cache.caches, CacheHandlerPatch):
+            cache.caches = middleware_cache.caches
+        else:
+            cache.caches = CacheHandlerPatch()
 
     def disable_instrumentation(self):
-        cache.cache = original_cache
-        cache.get_cache = original_get_cache
-
-    def process_response(self, request, response):
+        if django.VERSION[:2] < (1, 9):
+            cache.get_cache = original_get_cache
+        cache.caches = original_caches
+        # While it can be restored to the original, any views that were
+        # wrapped with the cache_page decorator will continue to use a
+        # monkey patched cache.
+        middleware_cache.caches = original_caches
+
+    def generate_stats(self, request, response):
         self.record_stats({
             'total_calls': len(self.calls),
             'calls': self.calls,
diff --git a/debug_toolbar/panels/headers.py b/debug_toolbar/panels/headers.py
index 3b941a9..cec5b09 100644
--- a/debug_toolbar/panels/headers.py
+++ b/debug_toolbar/panels/headers.py
@@ -1,10 +1,9 @@
 from __future__ import absolute_import, unicode_literals
 
-try:
-    from collections import OrderedDict
-except ImportError:
-    from django.utils.datastructures import SortedDict as OrderedDict
+from collections import OrderedDict
+
 from django.utils.translation import ugettext_lazy as _
+
 from debug_toolbar.panels import Panel
 
 
@@ -49,7 +48,7 @@ class HeadersPanel(Panel):
             'environ': self.environ,
         })
 
-    def process_response(self, request, response):
+    def generate_stats(self, request, response):
         self.response_headers = OrderedDict(sorted(response.items()))
         self.record_stats({
             'response_headers': self.response_headers,
diff --git a/debug_toolbar/panels/logging.py b/debug_toolbar/panels/logging.py
index 1ee19ce..db01179 100644
--- a/debug_toolbar/panels/logging.py
+++ b/debug_toolbar/panels/logging.py
@@ -2,13 +2,16 @@ from __future__ import absolute_import, unicode_literals
 
 import datetime
 import logging
+
+from django.utils.translation import ugettext_lazy as _, ungettext
+
+from debug_toolbar.panels import Panel
+from debug_toolbar.utils import ThreadCollector
+
 try:
... 3637 lines suppressed ...

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-django-debug-toolbar.git



More information about the Python-modules-commits mailing list