Browse Source

Django 4.0 compatible (#498)

* Fix for Django 4.0
* Replace some unnecessary re_path with path
Vince Salvino 2 years ago
parent
commit
cc317f3846

+ 2 - 2
coderedcms/admin_urls.py

@@ -1,4 +1,4 @@
-from django.urls import include, path, re_path
+from django.urls import include, path
 from wagtail.admin import urls as wagtailadmin_urls
 from wagtail.admin import urls as wagtailadmin_urls
 from coderedcms.views import import_index, import_pages_from_csv_file
 from coderedcms.views import import_index, import_pages_from_csv_file
 
 
@@ -8,5 +8,5 @@ urlpatterns = [
          import_index, name="import_index"),
          import_index, name="import_index"),
     path('codered/import-export/import_from_csv/',
     path('codered/import-export/import_from_csv/',
          import_pages_from_csv_file, name="import_from_csv"),
          import_pages_from_csv_file, name="import_from_csv"),
-    re_path(r'', include(wagtailadmin_urls)),
+    path('', include(wagtailadmin_urls)),
 ]
 ]

+ 1 - 1
coderedcms/importexport.py

@@ -14,7 +14,7 @@ from django import forms
 from django.apps import apps
 from django.apps import apps
 from django.contrib.contenttypes.models import ContentType
 from django.contrib.contenttypes.models import ContentType
 from django.db import models, transaction
 from django.db import models, transaction
-from django.utils.translation import ugettext as _
+from django.utils.translation import gettext as _
 from modelcluster.models import get_all_child_relations
 from modelcluster.models import get_all_child_relations
 from wagtail.admin.widgets import AdminPageChooser
 from wagtail.admin.widgets import AdminPageChooser
 from wagtail.core.models import Page
 from wagtail.core.models import Page

+ 3 - 3
coderedcms/project_template/basic/project_name/urls.py

@@ -1,5 +1,5 @@
 from django.conf import settings
 from django.conf import settings
-from django.urls import include, path, re_path
+from django.urls import include, path
 from django.contrib import admin
 from django.contrib import admin
 from wagtail.documents import urls as wagtaildocs_urls
 from wagtail.documents import urls as wagtaildocs_urls
 from coderedcms import admin_urls as coderedadmin_urls
 from coderedcms import admin_urls as coderedadmin_urls
@@ -20,11 +20,11 @@ urlpatterns = [
     # For anything not caught by a more specific rule above, hand over to
     # For anything not caught by a more specific rule above, hand over to
     # the page serving mechanism. This should be the last pattern in
     # the page serving mechanism. This should be the last pattern in
     # the list:
     # the list:
-    re_path(r'', include(codered_urls)),
+    path('', include(codered_urls)),
 
 
     # Alternatively, if you want CMS pages to be served from a subpath
     # Alternatively, if you want CMS pages to be served from a subpath
     # of your site, rather than the site root:
     # of your site, rather than the site root:
-    #    re_path(r"^pages/", include(codered_urls)),
+    #    path("pages/", include(codered_urls)),
 ]
 ]
 
 
 
 

+ 3 - 3
coderedcms/project_template/sass/project_name/urls.py

@@ -1,5 +1,5 @@
 from django.conf import settings
 from django.conf import settings
-from django.urls import include, path, re_path
+from django.urls import include, path
 from django.contrib import admin
 from django.contrib import admin
 from wagtail.documents import urls as wagtaildocs_urls
 from wagtail.documents import urls as wagtaildocs_urls
 from coderedcms import admin_urls as coderedadmin_urls
 from coderedcms import admin_urls as coderedadmin_urls
@@ -20,11 +20,11 @@ urlpatterns = [
     # For anything not caught by a more specific rule above, hand over to
     # For anything not caught by a more specific rule above, hand over to
     # the page serving mechanism. This should be the last pattern in
     # the page serving mechanism. This should be the last pattern in
     # the list:
     # the list:
-    re_path(r'', include(codered_urls)),
+    path('', include(codered_urls)),
 
 
     # Alternatively, if you want CMS pages to be served from a subpath
     # Alternatively, if you want CMS pages to be served from a subpath
     # of your site, rather than the site root:
     # of your site, rather than the site root:
-    #    re_path(r'^pages/', include(codered_urls)),
+    #    path("pages/", include(codered_urls)),
 ]
 ]
 
 
 
 

+ 2 - 2
coderedcms/search_urls.py

@@ -1,6 +1,6 @@
-from django.urls import re_path
+from django.urls import path
 from coderedcms.views import search
 from coderedcms.views import search
 
 
 urlpatterns = [
 urlpatterns = [
-    re_path(r'', search, name='codered_search'),
+    path('', search, name='codered_search'),
 ]
 ]

+ 4 - 4
coderedcms/urls.py

@@ -15,9 +15,9 @@ from coderedcms.views import (
 
 
 urlpatterns = [
 urlpatterns = [
     # CodeRed custom URLs
     # CodeRed custom URLs
-    re_path(r'^favicon\.ico$', favicon, name='codered_favicon'),
-    re_path(r'^robots\.txt$', robots, name='codered_robots'),
-    re_path(r'^sitemap\.xml$', sitemap, name='codered_sitemap'),
+    path(r'favicon.ico', favicon, name='codered_favicon'),
+    path(r'robots.txt', robots, name='codered_robots'),
+    path(r'sitemap.xml', sitemap, name='codered_sitemap'),
     re_path(r'^{0}(?P<path>.*)$'.format(
     re_path(r'^{0}(?P<path>.*)$'.format(
         crx_settings.CRX_PROTECTED_MEDIA_URL.lstrip('/')),
         crx_settings.CRX_PROTECTED_MEDIA_URL.lstrip('/')),
         serve_protected_file,
         serve_protected_file,
@@ -34,5 +34,5 @@ urlpatterns = [
     path('ajax/calendar/events/', event_get_calendar_events, name='event_get_calendar_events'),
     path('ajax/calendar/events/', event_get_calendar_events, name='event_get_calendar_events'),
 
 
     # Wagtail
     # Wagtail
-    re_path(r'', include(wagtailcore_urls)),
+    path('', include(wagtailcore_urls)),
 ]
 ]

+ 2 - 2
coderedcms/views.py

@@ -8,7 +8,7 @@ from django.contrib.contenttypes.models import ContentType
 from django.core.paginator import Paginator, InvalidPage, EmptyPage, PageNotAnInteger
 from django.core.paginator import Paginator, InvalidPage, EmptyPage, PageNotAnInteger
 from django.shortcuts import redirect, render
 from django.shortcuts import redirect, render
 from django.utils import timezone
 from django.utils import timezone
-from django.utils.translation import ungettext, gettext_lazy as _
+from django.utils.translation import ngettext, gettext_lazy as _
 from icalendar import Calendar
 from icalendar import Calendar
 from wagtail.admin import messages
 from wagtail.admin import messages
 from wagtail.search.backends import db, get_search_backend
 from wagtail.search.backends import db, get_search_backend
@@ -261,7 +261,7 @@ def import_pages_from_csv_file(request):
                     "Import failed: %(reason)s") % {'reason': e}
                     "Import failed: %(reason)s") % {'reason': e}
                 )
                 )
             else:
             else:
-                messages.success(request, ungettext(
+                messages.success(request, ngettext(
                     "%(count)s page imported.",
                     "%(count)s page imported.",
                     "%(count)s pages imported.",
                     "%(count)s pages imported.",
                     page_count) % {'count': page_count}
                     page_count) % {'count': page_count}

+ 5 - 4
coderedcms/wagtail_flexible_forms/wagtail_hooks.py

@@ -1,8 +1,7 @@
-from django.conf.urls import url
 from django.contrib.admin import SimpleListFilter
 from django.contrib.admin import SimpleListFilter
 from django.contrib.admin.utils import quote
 from django.contrib.admin.utils import quote
 from django.shortcuts import redirect
 from django.shortcuts import redirect
-from django.urls import reverse
+from django.urls import path, reverse
 from django.utils.translation import gettext_lazy as _
 from django.utils.translation import gettext_lazy as _
 from wagtail.contrib.modeladmin.helpers import (
 from wagtail.contrib.modeladmin.helpers import (
     PermissionHelper, PagePermissionHelper, PageAdminURLHelper, AdminURLHelper,
     PermissionHelper, PagePermissionHelper, PageAdminURLHelper, AdminURLHelper,
@@ -302,9 +301,11 @@ class SubmissionAdmin(ModelAdmin):
     def get_admin_urls_for_registration(self):
     def get_admin_urls_for_registration(self):
         urls = super().get_admin_urls_for_registration()
         urls = super().get_admin_urls_for_registration()
         urls += (
         urls += (
-            url(self.url_helper.get_action_url_pattern('set_status'),
+            path(
+                self.url_helper.get_action_url_pattern('set_status'),
                 self.set_status_view,
                 self.set_status_view,
-                name=self.url_helper.get_action_url_name('set_status')),
+                name=self.url_helper.get_action_url_name('set_status')
+            ),
         )
         )
         return urls
         return urls
 
 

+ 2 - 1
setup.py

@@ -34,6 +34,7 @@ setup(
         'Programming Language :: Python :: 3 :: Only',
         'Programming Language :: Python :: 3 :: Only',
         'Framework :: Django',
         'Framework :: Django',
         'Framework :: Django :: 3.2',
         'Framework :: Django :: 3.2',
+        'Framework :: Django :: 4.0',
         'Framework :: Wagtail',
         'Framework :: Wagtail',
         'Framework :: Wagtail :: 2',
         'Framework :: Wagtail :: 2',
         'Topic :: Internet :: WWW/HTTP',
         'Topic :: Internet :: WWW/HTTP',
@@ -45,7 +46,7 @@ setup(
         'beautifulsoup4>=4.8,<4.10',    # should be the same as wagtail
         'beautifulsoup4>=4.8,<4.10',    # should be the same as wagtail
         'django-eventtools==1.0.*',
         'django-eventtools==1.0.*',
         'django-bootstrap4==22.1',
         'django-bootstrap4==22.1',
-        'Django>=3.2,<4.0',             # should be the same as wagtail
+        'Django>=3.2,<4.1',             # should be the same as wagtail
         'geocoder==1.38.*',
         'geocoder==1.38.*',
         'icalendar==4.0.*',
         'icalendar==4.0.*',
         'wagtail==2.16.*',
         'wagtail==2.16.*',