From d819f97d6cc55f34299fee408f0a842bd18033bd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=BAnio=20Eduardo=20de=20Morais=20Aquino?=
<8471126+jeduardo211@users.noreply.github.com>
Date: Thu, 26 May 2022 06:11:19 -0300
Subject: [PATCH] Add support for Django 4 (#24)
* Use path instead of url to support Django 4
The old way of defining urls in DJango is no longer supported in Django 4.0.
This commit replaces the regular expression based paths by the more modern path method, and also adds app_name in the urls file to allow usage with URL namespaces.
* Increase version
Altered major version because old versions of Django cannot be supported anymore.
---
error_tracker/__init__.py | 2 +-
.../django/templates/error_tracker/base.html | 2 +-
.../error_tracker/partials/partial_table.html | 4 ++--
error_tracker/django/urls.py | 9 +++++----
error_tracker/django/views.py | 9 +++++----
setup.py | 2 ++
tests/DjangoTest/DjangoTest/drf_urls.py | 16 ++++++++--------
tests/DjangoTest/DjangoTest/urls.py | 12 ++++++------
8 files changed, 30 insertions(+), 26 deletions(-)
diff --git a/error_tracker/__init__.py b/error_tracker/__init__.py
index bc3b36f..db3bdd4 100644
--- a/error_tracker/__init__.py
+++ b/error_tracker/__init__.py
@@ -6,7 +6,7 @@
# :license: BSD-3-Clause
#
-__version__ = '2.1.0'
+__version__ = '3.0.0'
__author__ = 'Sonu Kumar'
__email__ = 'sonunitw12@gmail.com'
diff --git a/error_tracker/django/templates/error_tracker/base.html b/error_tracker/django/templates/error_tracker/base.html
index b8186e5..c8c9d99 100755
--- a/error_tracker/django/templates/error_tracker/base.html
+++ b/error_tracker/django/templates/error_tracker/base.html
@@ -38,7 +38,7 @@
{% block header_block %}
{% endblock %}
{% block content_block %}
diff --git a/error_tracker/django/templates/error_tracker/partials/partial_table.html b/error_tracker/django/templates/error_tracker/partials/partial_table.html
index 720c29a..3388f9b 100644
--- a/error_tracker/django/templates/error_tracker/partials/partial_table.html
+++ b/error_tracker/django/templates/error_tracker/partials/partial_table.html
@@ -4,7 +4,7 @@
{{ error.host }} |
{{ error.method }} |
-
+
{{ error.path|truncatechars:30 }}
|
@@ -12,7 +12,7 @@
{{ error.last_seen }} |
{{ error.count }} |
- {%trans 'Delete' %}
|
diff --git a/error_tracker/django/urls.py b/error_tracker/django/urls.py
index 85bc7be..e1b3047 100755
--- a/error_tracker/django/urls.py
+++ b/error_tracker/django/urls.py
@@ -6,11 +6,12 @@
# :license: BSD-3-Clause
#
-from django.conf.urls import url
+from django.urls import path
from .views import detail, view_list, delete_exception
+app_name = 'error_tracker'
urlpatterns = [
- url(r'^$', view_list, name="view_errors"),
- url(r'^(?P
[\w-]+)/delete$', delete_exception, name='delete_error'),
- url(r'^(?P[\w-]+)$', detail, name='view_error'),
+ path('', view_list, name="view_errors"),
+ path('/delete', delete_exception, name='delete_error'),
+ path('', detail, name='view_error'),
]
diff --git a/error_tracker/django/views.py b/error_tracker/django/views.py
index e83076a..df35a27 100644
--- a/error_tracker/django/views.py
+++ b/error_tracker/django/views.py
@@ -42,13 +42,14 @@ def view_list(request):
error = False
errors = model.get_exceptions_per_page(**query)
- next_url = reverse('view_errors') + "?page=" + str(errors.next_num) \
+ next_url = reverse('error_tracker:view_errors') + "?page=" + str(errors.next_num) \
if errors.has_next else None
- prev_url = reverse('view_errors') + "?page=" + str(errors.prev_num) \
+ prev_url = reverse('error_tracker:view_errors') + "?page=" + str(errors.prev_num) \
if errors.has_prev else None
- if request.is_ajax() or request.GET.get('ajax_partial'):
+ is_ajax = request.META.get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest'
+ if is_ajax or request.GET.get('ajax_partial'):
table = render_to_string('error_tracker/partials/partial_table.html', {
'errors': errors,
})
@@ -75,7 +76,7 @@ def delete_exception(request, rhash):
:return: redirect back to home page
"""
model.delete_entity(rhash)
- return redirect(reverse('view_errors'))
+ return redirect(reverse('error_tracker:view_errors'))
@require_GET
diff --git a/setup.py b/setup.py
index 4b290ab..42744ab 100755
--- a/setup.py
+++ b/setup.py
@@ -69,6 +69,8 @@ def grep(attrname):
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
+ 'Programming Language :: Python :: 3.9',
+ 'Programming Language :: Python :: 3.10',
'Topic :: Software Development :: Libraries :: Python Modules',
]
)
diff --git a/tests/DjangoTest/DjangoTest/drf_urls.py b/tests/DjangoTest/DjangoTest/drf_urls.py
index 939c976..2542732 100644
--- a/tests/DjangoTest/DjangoTest/drf_urls.py
+++ b/tests/DjangoTest/DjangoTest/drf_urls.py
@@ -1,4 +1,4 @@
-from django.conf.urls import url, include
+from django.urls import path, include
from django.contrib import admin
from rest_framework import routers
from error_tracker.django import urls
@@ -9,11 +9,11 @@
router.register(r'users', UserViewSet)
urlpatterns = [
- url('admin/', admin.site.urls),
- url("dev/", include(urls)),
- url(r'^$', views.index),
- url(r'^value-error$', views.value_error),
- url(r'^post-view$', views.post_view),
- url(r'^', include(router.urls)),
- url(r'^api-auth/', include('rest_framework.urls'))
+ path('admin/', admin.site.urls),
+ path('dev/', include(urls)),
+ path('', views.index),
+ path('value-error', views.value_error),
+ path('post-view', views.post_view),
+ path('', include(router.urls)),
+ path('api-auth/', include('rest_framework.urls'))
]
diff --git a/tests/DjangoTest/DjangoTest/urls.py b/tests/DjangoTest/DjangoTest/urls.py
index e22991c..b85bf2a 100644
--- a/tests/DjangoTest/DjangoTest/urls.py
+++ b/tests/DjangoTest/DjangoTest/urls.py
@@ -13,15 +13,15 @@
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
-from django.conf.urls import url, include
+from django.urls import path, include
from django.contrib import admin
from error_tracker.django import urls
from core import views
urlpatterns = [
- url('admin/', admin.site.urls),
- url("dev/", include(urls)),
- url(r'^$', views.index),
- url(r'^value-error$', views.value_error),
- url(r'^post-view$', views.post_view),
+ path('admin/', admin.site.urls),
+ path('dev/', include(urls)),
+ path('', views.index),
+ path('value-error', views.value_error),
+ path('post-view', views.post_view),
]