From edfef7cebdf958f8ec7250fd471ae62bfbdd0358 Mon Sep 17 00:00:00 2001 From: Cenk Alti Date: Sun, 21 Oct 2012 23:45:06 +0300 Subject: [PATCH 1/7] adapted to flask --- debug_toolbar_mongo/__init__.py | 7 +++++++ debug_toolbar_mongo/operation_tracker.py | 10 +--------- debug_toolbar_mongo/panel.py | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/debug_toolbar_mongo/__init__.py b/debug_toolbar_mongo/__init__.py index cbe4322..3cdb0e5 100644 --- a/debug_toolbar_mongo/__init__.py +++ b/debug_toolbar_mongo/__init__.py @@ -1,2 +1,9 @@ # following PEP 386, versiontools will pick it up __version__ = (0, 1, 7, "final", 0) + +import os + +os.environ['DJANGO_SETTINGS_MODULE'] = 'debug_toolbar_mongo' + +TEMPLATE_DIRS = (os.path.join(os.path.dirname(__file__), 'templates').replace('\\','/'), ) +INSTALLED_APPS = ('debug_toolbar_mongo', ) diff --git a/debug_toolbar_mongo/operation_tracker.py b/debug_toolbar_mongo/operation_tracker.py index 4063c5e..38f0182 100644 --- a/debug_toolbar_mongo/operation_tracker.py +++ b/debug_toolbar_mongo/operation_tracker.py @@ -4,9 +4,6 @@ import os import SocketServer -import django -from django.conf import settings - import pymongo import pymongo.collection import pymongo.cursor @@ -27,7 +24,7 @@ updates = [] removes = [] -WANT_STACK_TRACE = getattr(settings, 'DEBUG_TOOLBAR_MONGO_STACKTRACES', True) +WANT_STACK_TRACE = True #getattr(settings, 'DEBUG_TOOLBAR_MONGO_STACKTRACES', True) def _get_stacktrace(): if WANT_STACK_TRACE: try: @@ -226,8 +223,6 @@ def _tidy_stacktrace(stack): ``stack`` should be a list of frame tuples from ``inspect.stack()`` """ - django_path = os.path.realpath(os.path.dirname(django.__file__)) - django_path = os.path.normpath(os.path.join(django_path, '..')) socketserver_path = os.path.realpath(os.path.dirname(SocketServer.__file__)) pymongo_path = os.path.realpath(os.path.dirname(pymongo.__file__)) @@ -238,9 +233,6 @@ def _tidy_stacktrace(stack): # inspection. if '__traceback_hide__' in frame.f_locals: continue - if getattr(settings, 'DEBUG_TOOLBAR_CONFIG', {}).get('HIDE_DJANGO_SQL', True) \ - and django_path in s_path and not 'django/contrib' in s_path: - continue if socketserver_path in s_path: continue if pymongo_path in s_path: diff --git a/debug_toolbar_mongo/panel.py b/debug_toolbar_mongo/panel.py index b25ddcf..c30caa2 100644 --- a/debug_toolbar_mongo/panel.py +++ b/debug_toolbar_mongo/panel.py @@ -1,6 +1,6 @@ from django.template.loader import render_to_string -from debug_toolbar.panels import DebugPanel +from flask_debugtoolbar.panels import DebugPanel import operation_tracker From b28a7ee5e786b56c91bfe52b4d7aff25768901c8 Mon Sep 17 00:00:00 2001 From: Rodrigo Prado Date: Thu, 11 Jun 2015 08:31:08 -0300 Subject: [PATCH 2/7] Added syntax highlighting --- README.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.rst b/README.rst index 61ecfb6..9df5b63 100644 --- a/README.rst +++ b/README.rst @@ -9,6 +9,7 @@ Setup ===== Add the following lines to your ``settings.py``:: +``` INSTALLED_APPS = ( ... 'debug_toolbar_mongo', @@ -20,6 +21,7 @@ Add the following lines to your ``settings.py``:: 'debug_toolbar_mongo.panel.MongoDebugPanel', ... ) +``` An extra panel titled "MongoDB" should appear in your debug toolbar. @@ -28,7 +30,9 @@ Note that this should work with any Django application that uses PyMongo. Obtaining stack traces can slow down queries significantly. To turn them off add the following lines to your ``settings.py``:: +``` DEBUG_TOOLBAR_MONGO_STACKTRACES = False +``` Disclaimer: only tested in latest Chrome, may fall to pieces in other browers. If you feel like fixing it, contributions are welcome! From c32b970688ed4914c788a0f79c737c37205387da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cenk=20Alt=C4=B1?= Date: Fri, 12 Jun 2015 08:59:19 +0300 Subject: [PATCH 3/7] Revert "Added syntax highlighting" --- README.rst | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.rst b/README.rst index 9df5b63..61ecfb6 100644 --- a/README.rst +++ b/README.rst @@ -9,7 +9,6 @@ Setup ===== Add the following lines to your ``settings.py``:: -``` INSTALLED_APPS = ( ... 'debug_toolbar_mongo', @@ -21,7 +20,6 @@ Add the following lines to your ``settings.py``:: 'debug_toolbar_mongo.panel.MongoDebugPanel', ... ) -``` An extra panel titled "MongoDB" should appear in your debug toolbar. @@ -30,9 +28,7 @@ Note that this should work with any Django application that uses PyMongo. Obtaining stack traces can slow down queries significantly. To turn them off add the following lines to your ``settings.py``:: -``` DEBUG_TOOLBAR_MONGO_STACKTRACES = False -``` Disclaimer: only tested in latest Chrome, may fall to pieces in other browers. If you feel like fixing it, contributions are welcome! From 46954f362d9379c49ce0d23fbb31f2faf4127483 Mon Sep 17 00:00:00 2001 From: mohamed-aziz Date: Sat, 4 Feb 2017 15:31:15 +0000 Subject: [PATCH 4/7] Removed django stuff? --- debug_toolbar_mongo/__init__.py | 7 ------- debug_toolbar_mongo/operation_tracker.py | 4 ---- debug_toolbar_mongo/panel.py | 7 +++---- 3 files changed, 3 insertions(+), 15 deletions(-) diff --git a/debug_toolbar_mongo/__init__.py b/debug_toolbar_mongo/__init__.py index 3cdb0e5..cbe4322 100644 --- a/debug_toolbar_mongo/__init__.py +++ b/debug_toolbar_mongo/__init__.py @@ -1,9 +1,2 @@ # following PEP 386, versiontools will pick it up __version__ = (0, 1, 7, "final", 0) - -import os - -os.environ['DJANGO_SETTINGS_MODULE'] = 'debug_toolbar_mongo' - -TEMPLATE_DIRS = (os.path.join(os.path.dirname(__file__), 'templates').replace('\\','/'), ) -INSTALLED_APPS = ('debug_toolbar_mongo', ) diff --git a/debug_toolbar_mongo/operation_tracker.py b/debug_toolbar_mongo/operation_tracker.py index 38f0182..152a4c9 100644 --- a/debug_toolbar_mongo/operation_tracker.py +++ b/debug_toolbar_mongo/operation_tracker.py @@ -2,7 +2,6 @@ import time import inspect import os -import SocketServer import pymongo import pymongo.collection @@ -223,7 +222,6 @@ def _tidy_stacktrace(stack): ``stack`` should be a list of frame tuples from ``inspect.stack()`` """ - socketserver_path = os.path.realpath(os.path.dirname(SocketServer.__file__)) pymongo_path = os.path.realpath(os.path.dirname(pymongo.__file__)) trace = [] @@ -233,8 +231,6 @@ def _tidy_stacktrace(stack): # inspection. if '__traceback_hide__' in frame.f_locals: continue - if socketserver_path in s_path: - continue if pymongo_path in s_path: continue if not text: diff --git a/debug_toolbar_mongo/panel.py b/debug_toolbar_mongo/panel.py index c30caa2..c69f327 100644 --- a/debug_toolbar_mongo/panel.py +++ b/debug_toolbar_mongo/panel.py @@ -1,8 +1,7 @@ -from django.template.loader import render_to_string - +from flask import render_template from flask_debugtoolbar.panels import DebugPanel -import operation_tracker +from . import operation_tracker class MongoDebugPanel(DebugPanel): @@ -40,6 +39,6 @@ def content(self): context['inserts'] = operation_tracker.inserts context['updates'] = operation_tracker.updates context['removes'] = operation_tracker.removes - return render_to_string('mongo-panel.html', context) + return render_template('mongo-panel.html', **context) From a173bb7e0cc2279e7987633c3e0ef61e4bbfccad Mon Sep 17 00:00:00 2001 From: mohamed-aziz Date: Sat, 4 Feb 2017 16:40:55 +0000 Subject: [PATCH 5/7] Moving code to jinja2. --- debug_toolbar_mongo/panel.py | 10 +-- .../templates/mongo-panel.html | 68 +++++++++---------- 2 files changed, 38 insertions(+), 40 deletions(-) diff --git a/debug_toolbar_mongo/panel.py b/debug_toolbar_mongo/panel.py index c69f327..0c26044 100644 --- a/debug_toolbar_mongo/panel.py +++ b/debug_toolbar_mongo/panel.py @@ -1,6 +1,6 @@ -from flask import render_template from flask_debugtoolbar.panels import DebugPanel - +import jinja2 +import os from . import operation_tracker @@ -12,6 +12,8 @@ class MongoDebugPanel(DebugPanel): def __init__(self, *args, **kwargs): super(self.__class__, self).__init__(*args, **kwargs) + module_path = os.path.join(os.path.dirname(__file__), 'templates') + self.jinja_env = jinja2.Environment(loader=jinja2.FileSystemLoader(module_path)) operation_tracker.install_tracker() def process_request(self, request): @@ -39,6 +41,4 @@ def content(self): context['inserts'] = operation_tracker.inserts context['updates'] = operation_tracker.updates context['removes'] = operation_tracker.removes - return render_template('mongo-panel.html', **context) - - + return self.render('mongo-panel.html', context) diff --git a/debug_toolbar_mongo/templates/mongo-panel.html b/debug_toolbar_mongo/templates/mongo-panel.html index b6ab8d7..89bf214 100644 --- a/debug_toolbar_mongo/templates/mongo-panel.html +++ b/debug_toolbar_mongo/templates/mongo-panel.html @@ -1,5 +1,3 @@ -{% load mongo_debug_tags %} -