From 974610de036c298ee3b4a6b4bfd2d6652eff29c6 Mon Sep 17 00:00:00 2001 From: Mario Orlandi Date: Wed, 1 Oct 2014 17:53:56 +0200 Subject: [PATCH 1/2] Fixes for Django 1.7 compatibility --- profiler/templates/profiler/base.html | 19 ++++++++++--------- profiler/urls.py | 2 +- profiler/views.py | 4 ++-- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/profiler/templates/profiler/base.html b/profiler/templates/profiler/base.html index 953bcee..1bfd399 100644 --- a/profiler/templates/profiler/base.html +++ b/profiler/templates/profiler/base.html @@ -1,3 +1,4 @@ +{% load static %} @@ -8,12 +9,12 @@ - - + + - - + + @@ -29,10 +30,10 @@ @@ -44,7 +45,7 @@ {% endblock %} - + diff --git a/profiler/urls.py b/profiler/urls.py index 07f3b7f..2bf7edf 100644 --- a/profiler/urls.py +++ b/profiler/urls.py @@ -1,4 +1,4 @@ -from django.conf.urls.defaults import * +from django.conf.urls import patterns, url urlpatterns = patterns( 'profiler.views', diff --git a/profiler/views.py b/profiler/views.py index 150f3ba..3899b01 100644 --- a/profiler/views.py +++ b/profiler/views.py @@ -4,7 +4,7 @@ from django.core.cache import cache from django.contrib.auth.decorators import user_passes_test from django.core.urlresolvers import reverse -from django.utils import simplejson +import json from aggregate.client import get_client @@ -42,7 +42,7 @@ def stats_by_view(request): return render_to_response('profiler/by_view.html', {'queries' : grouped, - 'stats' :simplejson.dumps(stats)}, + 'stats' :json.dumps(stats)}, context_instance=RequestContext(request)) @user_passes_test(lambda u:u.is_superuser) From 8ff37012198941b3a68a34adefe7fe46eab421f7 Mon Sep 17 00:00:00 2001 From: Mario Orlandi Date: Sun, 5 Oct 2014 08:21:03 +0200 Subject: [PATCH 2/2] Restore backward compatibility for older versions of Django --- profiler/templates/profiler/base.html | 2 +- profiler/urls.py | 7 +++++-- profiler/views.py | 11 +++++++---- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/profiler/templates/profiler/base.html b/profiler/templates/profiler/base.html index 1bfd399..727767b 100644 --- a/profiler/templates/profiler/base.html +++ b/profiler/templates/profiler/base.html @@ -32,7 +32,7 @@ diff --git a/profiler/urls.py b/profiler/urls.py index 2bf7edf..bdcc292 100644 --- a/profiler/urls.py +++ b/profiler/urls.py @@ -1,4 +1,8 @@ -from django.conf.urls import patterns, url +try: + from django.conf.urls import patterns, url +except ImportError: + from django.conf.urls.defaults import patterns, url + urlpatterns = patterns( 'profiler.views', @@ -7,4 +11,3 @@ url(r'^code/$', 'python_stats', name='profiler_python_stats'), url(r'^reset/$', 'reset', name='profiler_reset'), ) - diff --git a/profiler/views.py b/profiler/views.py index 3899b01..4a1e8a5 100644 --- a/profiler/views.py +++ b/profiler/views.py @@ -4,6 +4,9 @@ from django.core.cache import cache from django.contrib.auth.decorators import user_passes_test from django.core.urlresolvers import reverse + +#from django.utils import simplejson +# See: https://docs.djangoproject.com/en/dev/releases/1.5/#system-version-of-simplejson-no-longer-used import json from aggregate.client import get_client @@ -23,23 +26,23 @@ def stats_by_view(request): grouped = {} for r in stats: if r['view'] not in grouped: - grouped[r['view']] = {'queries' : [], + grouped[r['view']] = {'queries' : [], 'count' : 0, 'time' : 0, 'average_time' : 0} grouped[r['view']]['queries'].append(r) grouped[r['view']]['count'] += r['count'] grouped[r['view']]['time'] += r['time'] - r['average_time'] = r['time'] / r['count'] + r['average_time'] = r['time'] / r['count'] grouped[r['view']]['average_time'] += r['average_time'] - + maxtime = 0 for r in stats: if r['average_time'] > maxtime: maxtime = r['average_time'] for r in stats: r['normtime'] = (0.0+r['average_time'])/maxtime - + return render_to_response('profiler/by_view.html', {'queries' : grouped, 'stats' :json.dumps(stats)},