Commit 8d4c1265 by Harry Marr

Make the query more readable

parent a2d77317
...@@ -61,7 +61,6 @@ class MongoOperationTracker(object): ...@@ -61,7 +61,6 @@ class MongoOperationTracker(object):
query_data['skip'] = query_son.get('skip') query_data['skip'] = query_son.get('skip')
query_data['limit'] = query_son.get('limit') query_data['limit'] = query_son.get('limit')
query_data['query'] = query_son['query'] query_data['query'] = query_son['query']
del query_son['count']
else: else:
# Normal Query # Normal Query
query_data['skip'] = privar('skip') query_data['skip'] = privar('skip')
......
{% 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;
font-size: 1.05em !important;
}
</style>
<table> <table>
<thead> <thead>
...@@ -17,8 +25,12 @@ ...@@ -17,8 +25,12 @@
<td>{{ query.time|floatformat:"4" }}</td> <td>{{ query.time|floatformat:"4" }}</td>
<td>{{ query.operation|title }}</td> <td>{{ query.operation|title }}</td>
<td>{{ query.collection }}</td> <td>{{ query.collection }}</td>
<td><code>{{ query.query|pprint }}</code></td> <td>
<td>{% if query.ordering %}{{ query.ordering }}{% endif %}</td> {% if query.query %}
<pre class="mongo-highlight">{{ query.query|format_dict|highlight_json|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.skip %}{{ query.skip }}{% endif %}</td>
<td>{% if query.limit %}{{ query.limit }}{% endif %}</td> <td>{% if query.limit %}{{ query.limit }}{% endif %}</td>
</tr> </tr>
......
from django import template
import pprint
register = template.Library()
@register.filter
def format_dict(value, width=60):
print width
return pprint.pformat(value, width=int(width))
@register.filter
def highlight_json(value):
try:
from pygments import highlight
from pygments.lexers import JavascriptLexer
from pygments.formatters import HtmlFormatter
except ImportError:
return value
# Can't use class-based colouring because the debug toolbar's css rules
# are more specific so take precedence
formatter = HtmlFormatter(style='friendly', nowrap=True, noclasses=True)
return highlight(value, JavascriptLexer(), formatter)
...@@ -45,4 +45,8 @@ DEBUG_TOOLBAR_PANELS = ( ...@@ -45,4 +45,8 @@ DEBUG_TOOLBAR_PANELS = (
ROOT_URLCONF = 'example.urls' ROOT_URLCONF = 'example.urls'
DEBUG_TOOLBAR_CONFIG = {
'SHOW_TOOLBAR_CALLBACK': lambda request: True,
}
INTERNAL_IPS = ('127.0.0.1',) INTERNAL_IPS = ('127.0.0.1',)
...@@ -9,11 +9,23 @@ db = conn.debug_test ...@@ -9,11 +9,23 @@ db = conn.debug_test
def index(request): def index(request):
list(db.test.find({'name': 'test'})) list(db.test.find({'name': 'test'}))
list(db.test.find({'name': 'test'}).skip(1)) list(db.test.find({'name': 'test', 'age': {'$lt': 134234}}).skip(1))
db.test.find({'name': 'test'}).count() db.test.find({'name': 'test'}).count()
db.test.find({'name': 'test'}).skip(1).count(with_limit_and_skip=True) db.test.find({'name': 'test'}).skip(1).count(with_limit_and_skip=True)
list(db.test.find({'name': 'test'}).sort('name')) list(db.test.find({'name': 'test'}).sort('name'))
sort_fields = [('name', pymongo.DESCENDING), ('date', pymongo.ASCENDING)] sort_fields = [('name', pymongo.DESCENDING), ('date', pymongo.ASCENDING)]
list(db.test.find({'name': 'test'}).sort(sort_fields)) list(db.test.find({'name': 'test'}).sort(sort_fields))
list(db.test.find({
'$or': [
{
'age': {'$lt': 50, '$gt': 18},
'paying': True,
},
{
'name': 'King of the world',
'paying': False,
}
]
}))
return render_to_response('index.html') return render_to_response('index.html')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment