Skip to content

Commit d1d00b1

Browse files
Created a new History Panel
1 parent cecb1f1 commit d1d00b1

31 files changed

+161
-9
lines changed

debug_toolbar/panels/__init__.py

100644100755
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def content(self):
4747
def record_stats(self, stats):
4848
toolbar = DebugToolbarMiddleware.get_current()
4949
panel_stats = toolbar.stats.get(self.slug)
50+
#print panel_stats
5051
if panel_stats:
5152
panel_stats.update(stats)
5253
else:

debug_toolbar/panels/cache.py

100644100755
File mode changed.

debug_toolbar/panels/headers.py

100644100755
File mode changed.

debug_toolbar/panels/history.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
try:
2+
import resource
3+
except ImportError:
4+
pass # Will fail on Win32 systems
5+
import time
6+
from django.template.loader import render_to_string
7+
from django.utils.translation import ugettext as _
8+
from debug_toolbar.panels import DebugPanel
9+
10+
11+
class AjaxHistoryPanel(DebugPanel):
12+
"""
13+
Panel that displays the time a response took in milliseconds.
14+
"""
15+
name = 'AjaxHistory'
16+
template = 'debug_toolbar/panels/history.html'
17+
18+
try: # if resource module not available, don't show content panel
19+
resource
20+
except NameError:
21+
has_content = False
22+
has_resource = False
23+
else:
24+
has_content = True
25+
has_resource = True
26+
27+
def process_request(self, request):
28+
pass
29+
def process_response(self, request, response):
30+
pass
31+
32+
def nav_title(self):
33+
return _('Ajax History')
34+
def nav_subtitle(self):
35+
return _('0 REQUESTS')
36+
37+
def title(self):
38+
return _('Ajax History')
39+
40+
def url(self):
41+
return ''

debug_toolbar/panels/logger.py

100644100755
File mode changed.

debug_toolbar/panels/profiling.py

100644100755
File mode changed.

debug_toolbar/panels/request_vars.py

100644100755
File mode changed.

debug_toolbar/panels/settings_vars.py

100644100755
File mode changed.

debug_toolbar/panels/signals.py

100644100755
File mode changed.

debug_toolbar/panels/sql.py

100644100755
File mode changed.

debug_toolbar/panels/template.py

100644100755
File mode changed.

debug_toolbar/panels/timer.py

100644100755
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@ def process_request(self, request):
3131

3232
def process_response(self, request, response):
3333
stats = {'total_time': (time.time() - self._start_time) * 1000}
34+
print 'has resource'
35+
print self.has_resource
3436
if self.has_resource:
3537
self._end_rusage = resource.getrusage(resource.RUSAGE_SELF)
38+
print 'end rusage'
39+
print self._end_rusage
3640
stats['utime'] = 1000 * self._elapsed_ru('ru_utime')
3741
stats['stime'] = 1000 * self._elapsed_ru('ru_stime')
3842
stats['total'] = stats['utime'] + stats['stime']

debug_toolbar/panels/version.py

100644100755
File mode changed.

debug_toolbar/templates/debug_toolbar/base.html

Lines changed: 92 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,57 @@
88
<script type="text/javascript">
99
window.total_time_first_run = true;
1010
window.total_time = 0.0;
11+
window.toolbars = [];
12+
1113
window.total_time_accross_requests = function(){
1214
return 'The total time accross requests is: ' + window.total_time + 'ms';
1315
}
1416

17+
window.show_toolbar = function(index){
18+
$('#djDebug').replaceWith(window.toolbars[index].html);
19+
$('#djDebug').show();
20+
window.djdt.show_toolbar();
21+
for (i in window.toolbars){
22+
window.createHistoryTable(i);
23+
}
24+
$('.djDebugAjaxHistoryPanel small').html(window.toolbars.length + ' REQUESTS');
25+
}
26+
window.createHistoryTable = function(index){
27+
var tbody = $('#history_panel_body');
28+
var style_type = '';
29+
if ( ( index % 2 ) == 0){
30+
style_type = 'djDebugEven';
31+
} else {
32+
style_type = 'djDebugOdd';
33+
}
34+
35+
var html = '';
36+
37+
toolbar = window.toolbars[index];
38+
39+
html += '<tr class="' + style_type + '">';
40+
html += '<td>' + toolbar.settings.url + '</td>';
41+
html += '<td> <a href="#" onclick="window.show_toolbar('+index+')"> click here to show this toolbar </a>';
42+
html += '<td>'+toolbar.time + 'ms</td>';
43+
html += '</tr>';
44+
45+
tbody.html(tbody.html() + html);
46+
}
1547

1648
$(document).ready(function() {
1749
$(document).ajaxSuccess(function(e, xhr, settings) {
50+
console.log('e');
51+
console.log(e);
52+
console.log('xhr');
53+
console.log(xhr);
1854
var data;
1955
if (xhr.responseText.length > 5){
2056
data = $.parseJSON(xhr.responseText);
2157
}
22-
window.refreshDjdt(data);
58+
window.refreshDjdt(data, e, xhr, settings);
2359

2460
console.log(settings);
61+
console.log(settings.url);
2562
});
2663
});
2764
/*!
@@ -98,33 +135,79 @@ <h3>{{ panel.title|safe }}</h3>
98135
{% endfor %}
99136
<div id="djDebugWindow" class="panelContent"></div>
100137
</div>
101-
138+
<a rel='facebox' href='#message_popover' id='message_handle'></a>
139+
<div id='message_popover' style='display:none;'>
140+
<div style='padding:10px;' class='pop_message'></div>
141+
</div>
142+
<a rel='facebox' href='#address_select_popover' id='address_handle'></a>
143+
<div id='address_select_popover' style='display:none;'>
144+
<div style='padding:10px;font-size:14px;width:700px;'>
145+
<span style='font-weight:bold;'>Please choose which version of the address you want to use:</span><br/><br/>
146+
<table>
147+
<tr><td>Original address:</td><td><input type='radio' name='selected_address' class='selected_address' value='orig'/></td><td class='old_add'></td></tr>
148+
<tr><td>Suggested Address:</td><td><input type='radio' name='selected_address' class='selected_address' value='new'/></td><td class='new_add'></td></tr>
149+
</table>
150+
<div class='wrap-sbmt clr'>
151+
<input id='select_this_address' class='bth arrow select_this_address' type='submit' value='Use this Address' />
152+
</div>
153+
</div>
154+
</div>
155+
<style>#facebox .content{padding:0!important;}.select_this_address{cursor:pointer;color:green;}#lat_long{color:#0E6F3A;float:right;font-size:14px;position:relative;top:74px;cursor:pointer;}</style>
156+
102157
<script type="text/javascript">
103158

104-
window.refreshDjdt = function(ajax_data){
159+
window.refreshDjdt = function(ajax_data, e, xhr, settings){
105160
console.log('refreshing');
106161
console.log(ajax_data);
107-
console.log(ajax_data);
162+
108163
if (ajax_data == 'OK'){
109164
return false;
110165
}
111166
if (ajax_data == undefined){
112167
return false;
113168
}
169+
var toolbar = {};
170+
var time;
171+
toolbar['e'] = e;
172+
toolbar['xhr'] = xhr;
173+
toolbar['settings'] = settings;
114174
var v = ajax_data.replace;
115175
indexOfdjDebug = v.rendered.indexOf('<div id="djDebug"');
116176
v.rendered = v.rendered.substr(indexOfdjDebug,v.length);
177+
178+
117179
if (window.total_time_first_run){
118-
window.total_time += parseFloat($('.djDebugTimerPanel small').html().split('(')[1].split(')')[0].split('ms')[0]);
180+
181+
182+
toolbar['html'] = $('#djDebug').html();
183+
time = parseFloat($('.djDebugTimerPanel small').html().split('(')[1].split(')')[0].split('ms')[0]);
184+
185+
window.total_time += time;
186+
toolbar['time'] = time;
187+
window.toolbars.push(toolbar);
119188
window.total_time_first_run = false;
120189
}
121190

122191
$('#djDebug').replaceWith(v.rendered);
123-
124-
window.total_time += parseFloat($('.djDebugTimerPanel small').html().split('(')[1].split(')')[0].split('ms')[0]);
125-
192+
toolbar['html'] = v.rendered;
193+
194+
$('.djDebugAjaxHistoryPanel small').html(window.toolbars.length + ' REQUESTS');
195+
time = parseFloat($('.djDebugTimerPanel small').html().split('(')[1].split(')')[0].split('ms')[0]);
196+
window.total_time += time;
197+
toolbar['time'] = time;
198+
window.toolbars.push(toolbar);
199+
for (i in window.toolbars){
200+
window.createHistoryTable(i);
201+
}
126202
$('#djDebug').show();
127203
window.djdt.show_toolbar();
128-
//window.djdt = window.djdt.init()
204+
205+
warning_time = 7000.00
206+
if (parseFloat(time) > warning_time){
207+
$('#message_handle').facebox().click();
208+
$('.pop_message').html('You have a request that took over '+(warning_time/1000)+' seconds (' + (parseFloat(time)/1000) + ')');
209+
}
129210
}
211+
212+
130213
</script>

debug_toolbar/templates/debug_toolbar/panels/cache.html

100644100755
File mode changed.

debug_toolbar/templates/debug_toolbar/panels/headers.html

100644100755
File mode changed.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{% load i18n %}
2+
<table>
3+
<colgroup>
4+
<col style="width:20%"/>
5+
<col/>
6+
</colgroup>
7+
<thead>
8+
<tr>
9+
<th>{% trans "Resource" %}</th>
10+
<th>{% trans "Value" %}</th>
11+
<th>{% trans "Elapsed Time(ms)" %}</th>
12+
</tr>
13+
</thead>
14+
<tbody id='history_panel_body'>
15+
{% for key, value in rows %}
16+
<tr class="">
17+
<td>{{ key|escape }}</td>
18+
<td>{{ value|escape }}</td>
19+
<td></td>
20+
</tr>
21+
{% endfor %}
22+
</tbody>
23+
</table>

debug_toolbar/templates/debug_toolbar/panels/logger.html

100644100755
File mode changed.

debug_toolbar/templates/debug_toolbar/panels/profiling.html

100644100755
File mode changed.

debug_toolbar/templates/debug_toolbar/panels/request_vars.html

100644100755
File mode changed.

debug_toolbar/templates/debug_toolbar/panels/settings_vars.html

100644100755
File mode changed.

debug_toolbar/templates/debug_toolbar/panels/signals.html

100644100755
File mode changed.

debug_toolbar/templates/debug_toolbar/panels/sql.html

100644100755
File mode changed.

debug_toolbar/templates/debug_toolbar/panels/sql_explain.html

100644100755
File mode changed.

debug_toolbar/templates/debug_toolbar/panels/sql_profile.html

100644100755
File mode changed.

debug_toolbar/templates/debug_toolbar/panels/sql_select.html

100644100755
File mode changed.

debug_toolbar/templates/debug_toolbar/panels/template_source.html

100644100755
File mode changed.

debug_toolbar/templates/debug_toolbar/panels/templates.html

100644100755
File mode changed.

debug_toolbar/templates/debug_toolbar/panels/timer.html

100644100755
File mode changed.

debug_toolbar/templates/debug_toolbar/panels/versions.html

100644100755
File mode changed.

debug_toolbar/templates/debug_toolbar/redirect.html

100644100755
File mode changed.

0 commit comments

Comments
 (0)