diff --git a/MANIFEST.in b/MANIFEST.in index ccb4d1b..80bb895 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,3 @@ include LICENSE include README.rst -include debug_toolbar_mongo/templates/* \ No newline at end of file +include flask_debug_toolbar_mongo/templates/* diff --git a/README.rst b/README.rst index 61ecfb6..ecb9464 100644 --- a/README.rst +++ b/README.rst @@ -1,5 +1,5 @@ ================================== -Django Debug Toolbar MongoDB Panel +Flask Debug Toolbar MongoDB Panel ================================== :Info: An extension panel for Rob Hudson's Django Debug Toolbar that adds MongoDB debugging information @@ -7,28 +7,15 @@ Django Debug Toolbar MongoDB Panel Setup ===== -Add the following lines to your ``settings.py``:: - INSTALLED_APPS = ( - ... - 'debug_toolbar_mongo', - ... - ) - DEBUG_TOOLBAR_PANELS = ( - ... - 'debug_toolbar_mongo.panel.MongoDebugPanel', - ... - ) +Set this in your Flask config object. -An extra panel titled "MongoDB" should appear in your debug toolbar. -Note that this should work with any Django application that uses PyMongo. + 'DEBUG_TB_PANELS': { + 'flask_debug_toolbar_mongo.panel.MongoDebugPanel' + } -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! +An extra panel titled "MongoDB" should appear in your debug toolbar. diff --git a/debug_toolbar_mongo/__init__.py b/flask_debug_toolbar_mongo/__init__.py similarity index 100% rename from debug_toolbar_mongo/__init__.py rename to flask_debug_toolbar_mongo/__init__.py diff --git a/debug_toolbar_mongo/operation_tracker.py b/flask_debug_toolbar_mongo/operation_tracker.py similarity index 91% rename from debug_toolbar_mongo/operation_tracker.py rename to flask_debug_toolbar_mongo/operation_tracker.py index 4063c5e..afdb9a6 100644 --- a/debug_toolbar_mongo/operation_tracker.py +++ b/flask_debug_toolbar_mongo/operation_tracker.py @@ -2,10 +2,6 @@ import time import inspect import os -import SocketServer - -import django -from django.conf import settings import pymongo import pymongo.collection @@ -27,7 +23,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: @@ -157,7 +153,7 @@ def privar(name): query_data['operation'] = 'command' # Handle count as a special case if 'count' in query_son: - # Information is in a different format to a standar query + # Information is in a different format to a standard query query_data['collection'] = query_son['count'] query_data['operation'] = 'count' query_data['skip'] = query_son.get('skip') @@ -226,9 +222,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__)) trace = [] @@ -238,11 +231,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: continue if not text: diff --git a/debug_toolbar_mongo/panel.py b/flask_debug_toolbar_mongo/panel.py similarity index 77% rename from debug_toolbar_mongo/panel.py rename to flask_debug_toolbar_mongo/panel.py index b25ddcf..0c26044 100644 --- a/debug_toolbar_mongo/panel.py +++ b/flask_debug_toolbar_mongo/panel.py @@ -1,8 +1,7 @@ -from django.template.loader import render_to_string - -from debug_toolbar.panels import DebugPanel - -import operation_tracker +from flask_debugtoolbar.panels import DebugPanel +import jinja2 +import os +from . import operation_tracker class MongoDebugPanel(DebugPanel): @@ -13,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): @@ -40,6 +41,4 @@ 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 self.render('mongo-panel.html', context) diff --git a/debug_toolbar_mongo/templates/mongo-panel.html b/flask_debug_toolbar_mongo/templates/mongo-panel.html similarity index 78% rename from debug_toolbar_mongo/templates/mongo-panel.html rename to flask_debug_toolbar_mongo/templates/mongo-panel.html index b6ab8d7..89bf214 100644 --- a/debug_toolbar_mongo/templates/mongo-panel.html +++ b/flask_debug_toolbar_mongo/templates/mongo-panel.html @@ -1,5 +1,3 @@ -{% load mongo_debug_tags %} -