From c83e6de6b077133716e2bdfd5bed72016e719a52 Mon Sep 17 00:00:00 2001 From: nikhila05 Date: Mon, 5 Mar 2018 17:41:33 +0530 Subject: [PATCH] updated to django 2.0 --- django_web_profiler/middleware.py | 3 +- django_web_profiler/models.py | 4 +-- .../templatetags/profile_tags.py | 3 +- django_web_profiler/urls.py | 4 ++- docs/source/conf.py | 4 +-- sandbox/requirementx.txt | 2 +- sandbox/testingapp/tests.py | 29 ++++++++++++++----- setup.py | 4 +-- 8 files changed, 32 insertions(+), 21 deletions(-) diff --git a/django_web_profiler/middleware.py b/django_web_profiler/middleware.py index 5976c50..8ad0126 100644 --- a/django_web_profiler/middleware.py +++ b/django_web_profiler/middleware.py @@ -83,7 +83,6 @@ def process_response(self, request, response): if settings.DEBUG: toolbar = self.__class__.debug_toolbars.pop( threading.current_thread().ident, None) - if not toolbar: return response @@ -228,5 +227,5 @@ def process_response(self, request, response): except: request_details['system_cpu_time'] = 0 request.statistics = request_details - + logger1.debug(statistics) return response diff --git a/django_web_profiler/models.py b/django_web_profiler/models.py index 63d6dc9..4befb70 100644 --- a/django_web_profiler/models.py +++ b/django_web_profiler/models.py @@ -1,6 +1,4 @@ -from django.core.urlresolvers import reverse from django.db import models -from django.template.defaultfilters import date as date_filter class ProfileLog(models.Model): @@ -35,7 +33,7 @@ class ProfileLogRecord(models.Model): """Captures statistics for individual requests.""" timestamp = models.DateTimeField(auto_now_add=True) profile_log = models.ForeignKey( - ProfileLog, blank=True, null=True, related_name='profile_log') + ProfileLog, blank=True, null=True, related_name='profile_log', on_delete=models.CASCADE) request_path = models.CharField(max_length=255) ip_address = models.CharField(max_length=255) diff --git a/django_web_profiler/templatetags/profile_tags.py b/django_web_profiler/templatetags/profile_tags.py index 52d948c..13d4735 100644 --- a/django_web_profiler/templatetags/profile_tags.py +++ b/django_web_profiler/templatetags/profile_tags.py @@ -3,7 +3,7 @@ register = template.Library() -@register.assignment_tag(takes_context=True) +@register.simple_tag(takes_context=True) def get_page(context, page, no_pages): if page <= 3: start_page = 1 @@ -20,4 +20,3 @@ def get_page(context, page, no_pages): pages = range(start_page, end_page + 1) return pages - diff --git a/django_web_profiler/urls.py b/django_web_profiler/urls.py index b16f04c..03ff2e1 100644 --- a/django_web_profiler/urls.py +++ b/django_web_profiler/urls.py @@ -1,6 +1,8 @@ from django.conf.urls import url from .views import (index, records_list, device_records_list) +app_name = 'django_web_profiler' + urlpatterns = [ # url(r'^home/$','home'), url(r'^$', index, name="index"), @@ -8,4 +10,4 @@ url(r'^device-records-list/$', device_records_list, name='device_records_list'), -] \ No newline at end of file +] diff --git a/docs/source/conf.py b/docs/source/conf.py index b39f877..e96c6dc 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -51,9 +51,9 @@ # built documents. # # The short X.Y version. -version = '0.0.1' +version = '0.1.4' # The full version, including alpha/beta/rc tags. -release = '0.0.1' +release = '0.1.4' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/sandbox/requirementx.txt b/sandbox/requirementx.txt index 60b487c..73784bb 100644 --- a/sandbox/requirementx.txt +++ b/sandbox/requirementx.txt @@ -1,5 +1,5 @@ Django==1.11.2 django-compressor==2.1.1 django-debug-toolbar==1.8 -django-web-profiler==0.1.2 +django-web-profiler==0.1.3 requests==2.17.3 \ No newline at end of file diff --git a/sandbox/testingapp/tests.py b/sandbox/testingapp/tests.py index f12ba70..c73d089 100644 --- a/sandbox/testingapp/tests.py +++ b/sandbox/testingapp/tests.py @@ -1,8 +1,9 @@ from django.test import TestCase from django.core.urlresolvers import reverse from django.contrib.auth.models import User -from django_web_profiler.models import ProfileLog +from django_web_profiler.models import ProfileLogRecord from django.core.management import call_command +from django.test import Client # Create your tests here. @@ -12,7 +13,6 @@ def setUp(self): for i in range(0, 20): User.objects.create(username='test_' + str(i), email='test_' + str(i)) - def test_index(self): response = self.client.get('/') self.assertEqual(response.status_code, 200) @@ -22,7 +22,6 @@ def test_index(self): self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'profiler_base.html') - def test_logs(self): response = self.client.get('/profiler/device-records-list/') self.assertEqual(response.status_code, 200) @@ -34,11 +33,25 @@ def test_management_command(self): call_command('logging_urls', *args, **opts) - # def test_log_detail(self): # self.log = ProfileLog.objects.first() # print (self.log) - # url = reverse('django_web_profiler:records_list', kwargs={'record_id': self.log.id}) - # response = self.client.get(url) - # self.assertEqual(response.status_code, 200) - # self.assertTemplateUsed(response, 'log_detail.html') + # if self.log: + # url = reverse('django_web_profiler:records_list', kwargs={'record_id': self.log.id}) + # response = self.client.get(url) + # self.assertEqual(response.status_code, 200) + # self.assertTemplateUsed(response, 'log_detail.html') + + +class TestAppViews(TestCase): + client = Client() + + def test_ip_graph(self): + response = self.client.get('/ip/graph/') + self.assertEqual(response.status_code, 200) + self.assertTemplateUsed(response, 'ip_graph.html') + + def test_path_graph(self): + response = self.client.get('/path/graph/') + self.assertEqual(response.status_code, 200) + self.assertTemplateUsed(response, 'path_graph.html') diff --git a/setup.py b/setup.py index f6b797a..01a4f1e 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ setup( name='django-web-profiler', - version='0.1.2', + version='0.1.4', packages=find_packages(exclude=['tests', 'tests.*']), include_package_data=True, description="a django profiling tool which logs, stores debug toolbar statistics and also a set of URL's statistics using a management command.", @@ -45,6 +45,6 @@ 'Topic :: Internet :: WWW/HTTP :: Dynamic Content', ], install_requires=[ - "Django>=1.6.0,<1.11", + "Django", ], )