Skip to content
This repository has been archived by the owner on Nov 20, 2022. It is now read-only.

docs: Fix simple typo, standar -> standard #27

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
include LICENSE
include README.rst
include debug_toolbar_mongo/templates/*
include flask_debug_toolbar_mongo/templates/*
25 changes: 6 additions & 19 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,34 +1,21 @@
==================================
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
:Author: Harry Marr (http://github.com/hmarr, http://twitter.com/harrymarr)

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.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
import time
import inspect
import os
import SocketServer

import django
from django.conf import settings

import pymongo
import pymongo.collection
Expand All @@ -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:
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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 = []
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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)
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{% load mongo_debug_tags %}

<style type="text/css">
pre.mongo-highlight, pre.mongo-highlight span {
font-family: 'Consolas', 'Deja Vu Sans Mono', 'Bitstream Vera Sans Mono', 'Monaco', 'Courier New', monospace !important;
Expand Down Expand Up @@ -36,23 +34,23 @@ <h4>Queries</h4>
</thead>
<tbody>
{% for query in queries %}
<tr class="{% cycle 'djDebugOdd' 'djDebugEven' %}">
<td>{{ query.time|floatformat:"4" }}</td>
<tr class="{{ loop.cycle('flDebugOdd', 'flDebugEven') }}">
<td>{{ query.time }}</td>
<td>{{ query.operation|title }}</td>
<td>{{ query.collection }}</td>
<td>
{% if query.query %}
<pre class="mongo-highlight">{{ query.query|format_dict|highlight:"javascript"|safe }}</pre>
<pre class="mongo-highlight">{{ query.query|safe }}</pre>
{% endif %}
</td>
<td><pre class="mongo-highlight">{% if query.ordering %}{{ query.ordering }}{% endif %}</pre></td>
<td>{% if query.skip %}{{ query.skip }}{% endif %}</td>
<td>{% if query.limit %}{{ query.limit }}{% endif %}</td>
<td><a href="javascript:void(0);" class="mongo-toggle-trace" data-row="queries-{{ forloop.counter }}">Toggle</a></td>
<td><a href="javascript:void(0);" class="mongo-toggle-trace" data-row="queries-{{ loop.counter }}">Toggle</a></td>
</tr>
<tr class="{% cycle 'djDebugOdd' 'djDebugEven' %}">
<tr class="{{ loop.cycle('flDebugOdd', 'flDebugEven') }}">
<td colspan="8">
<table class="mongo-stack-trace "id="mongo-stack-trace-queries-{{ forloop.counter }}">
<table class="mongo-stack-trace "id="mongo-stack-trace-queries-{{ loop.counter }}">
<thead>
<tr>
<th>Line</th>
Expand All @@ -65,9 +63,9 @@ <h4>Queries</h4>
{% for line in query.stack_trace %}
<tr>
<td class="lineno">{{ line.1 }}</td>
<td class="file">{{ line.0|embolden_file }}</td>
<td class="file">{{ line.0 }}</td>
<td class="function">{{ line.2 }}</td>
<td class="code">{{ line.3|highlight:"python"|safe }}</td>
<td class="code">{{ line.3|safe }}</td>
</tr>
{% endfor %}
</tbody>
Expand All @@ -94,17 +92,17 @@ <h4>Inserts</h4>
</thead>
<tbody>
{% for insert in inserts %}
<tr class="{% cycle 'djDebugOdd' 'djDebugEven' %}">
<td>{{ insert.time|floatformat:"4" }}</td>
<tr class="{{ loop.cycle('flDebugOdd', 'flDebugEven') }}">
<td>{{ insert.time }}</td>
<td>
<pre class="mongo-highlight">{{ insert.document|format_dict:120|highlight:"javascript"|safe }}</pre>
<pre class="mongo-highlight">{{ insert.document|safe }}</pre>
</td>
<td>{{ insert.safe }}</td>
<td><a href="javascript:void(0);" class="mongo-toggle-trace" data-row="inserts-{{ forloop.counter }}">Toggle</a></td>
<td><a href="javascript:void(0);" class="mongo-toggle-trace" data-row="inserts-{{ loop.counter }}">Toggle</a></td>
</tr>
<tr class="{% cycle 'djDebugOdd' 'djDebugEven' %}">
<tr class="{{ loop.cycle('flDebugOdd', 'flDebugEven') }}">
<td colspan="4">
<table class="mongo-stack-trace "id="mongo-stack-trace-inserts-{{ forloop.counter }}">
<table class="mongo-stack-trace "id="mongo-stack-trace-inserts-{{ loop.counter }}">
<thead>
<tr>
<th>Line</th>
Expand All @@ -117,9 +115,9 @@ <h4>Inserts</h4>
{% for line in insert.stack_trace %}
<tr>
<td class="lineno">{{ line.1 }}</td>
<td class="file">{{ line.0|embolden_file }}</td>
<td class="file">{{ line.0 }}</td>
<td class="function">{{ line.2 }}</td>
<td class="code">{{ line.3|highlight:"python"|safe }}</td>
<td class="code">{{ line.3|safe }}</td>
</tr>
{% endfor %}
</tbody>
Expand All @@ -146,17 +144,17 @@ <h4>Removes</h4>
</thead>
<tbody>
{% for remove in removes %}
<tr class="{% cycle 'djDebugOdd' 'djDebugEven' %}">
<td>{{ remove.time|floatformat:"4" }}</td>
<tr class="{{ loop.cycle('flDebugOdd', 'flDebugEven') }}">
<td>{{ remove.time }}</td>
<td>
<pre class="mongo-highlight">{{ remove.spec_or_id|format_dict:120|highlight:"javascript"|safe }}</pre>
<pre class="mongo-highlight">{{ remove.spec_or_id|safe }}</pre>
</td>
<td>{{ remove.safe }}</td>
<td><a href="javascript:void(0);" class="mongo-toggle-trace" data-row="removes-{{ forloop.counter }}">Toggle</a></td>
<td><a href="javascript:void(0);" class="mongo-toggle-trace" data-row="removes-{{ loop.counter }}">Toggle</a></td>
</tr>
<tr class="{% cycle 'djDebugOdd' 'djDebugEven' %}">
<tr class="{{ loop.cycle('flDebugOdd', 'flDebugEven') }}">
<td colspan="4">
<table class="mongo-stack-trace "id="mongo-stack-trace-removes-{{ forloop.counter }}">
<table class="mongo-stack-trace "id="mongo-stack-trace-removes-{{ loop.counter }}">
<thead>
<tr>
<th>Line</th>
Expand All @@ -169,9 +167,9 @@ <h4>Removes</h4>
{% for line in remove.stack_trace %}
<tr>
<td class="lineno">{{ line.1 }}</td>
<td class="file">{{ line.0|embolden_file }}</td>
<td class="file">{{ line.0 }}</td>
<td class="function">{{ line.2 }}</td>
<td class="code">{{ line.3|highlight:"python"|safe }}</td>
<td class="code">{{ line.3|safe }}</td>
</tr>
{% endfor %}
</tbody>
Expand Down Expand Up @@ -201,22 +199,22 @@ <h4>Updates</h4>
</thead>
<tbody>
{% for update in updates %}
<tr class="{% cycle 'djDebugOdd' 'djDebugEven' %}">
<td>{{ update.time|floatformat:"4" }}</td>
<tr class="{{ loop.cycle('flDebugOdd', 'flDebugEven') }}">
<td>{{ update.time }}</td>
<td>
<pre class="mongo-highlight">{{ update.spec|format_dict:120|highlight:"javascript"|safe }}</pre>
<pre class="mongo-highlight">{{ update.spec|safe }}</pre>
</td>
<td>
<pre class="mongo-highlight">{{ update.document|format_dict:120|highlight:"javascript"|safe }}</pre>
<pre class="mongo-highlight">{{ update.document|safe }}</pre>
</td>
<td>{{ update.safe }}</td>
<td>{{ update.multi }}</td>
<td>{{ update.upsert }}</td>
<td><a href="javascript:void(0);" class="mongo-toggle-trace" data-row="updates-{{ forloop.counter }}">Toggle</a></td>
<td><a href="javascript:void(0);" class="mongo-toggle-trace" data-row="updates-{{ loop.counter }}">Toggle</a></td>
</tr>
<tr class="{% cycle 'djDebugOdd' 'djDebugEven' %}">
<tr class="{{ loop.cycle('flDebugOdd', 'flDebugEven') }}">
<td colspan="7">
<table class="mongo-stack-trace "id="mongo-stack-trace-updates-{{ forloop.counter }}">
<table class="mongo-stack-trace "id="mongo-stack-trace-updates-{{ loop.counter }}">
<thead>
<tr>
<th>Line</th>
Expand All @@ -229,9 +227,9 @@ <h4>Updates</h4>
{% for line in update.stack_trace %}
<tr>
<td class="lineno">{{ line.1 }}</td>
<td class="file">{{ line.0|embolden_file }}</td>
<td class="file">{{ line.0 }}</td>
<td class="function">{{ line.2 }}</td>
<td class="code">{{ line.3|highlight:"python"|safe }}</td>
<td class="code">{{ line.3|safe }}</td>
</tr>
{% endfor %}
</tbody>
Expand Down
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from setuptools import setup, find_packages

setup(
name='django-debug-toolbar-mongo',
version=":versiontools:debug_toolbar_mongo:",
description='MongoDB panel for the Django Debug Toolbar',
name='flask-debug-toolbar-mongo',
version=":versiontools:flask_debug_toolbar_mongo:",
description='MongoDB panel for the Flask Debug Toolbar',
long_description=open('README.rst').read(),
author='Harry Marr',
author_email='[email protected]',
Expand All @@ -17,7 +17,7 @@
],
classifiers=[
'Environment :: Web Environment',
'Framework :: Django',
'Framework :: Flask',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
Expand Down