Skip to content

Commit

Permalink
Moving code to jinja2.
Browse files Browse the repository at this point in the history
  • Loading branch information
realazizk committed Feb 4, 2017
1 parent 46954f3 commit a173bb7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 40 deletions.
10 changes: 5 additions & 5 deletions 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


Expand All @@ -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):
Expand Down Expand Up @@ -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)
68 changes: 33 additions & 35 deletions debug_toolbar_mongo/templates/mongo-panel.html
@@ -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

0 comments on commit a173bb7

Please sign in to comment.