Repository: CiviWiki/OpenCiviWiki

Issue:
Update Django to 4.0.1
We need to update Django to 4, i.e. the latest version, in this project. Otherwise, security checks fail.

- [ ] Change requirements file to include Django 4
- [ ] Make modifications to run the project with Django 4


Discussion:

Resolving patch:
diff --git a/project/accounts/forms.py b/project/accounts/forms.py
--- a/project/accounts/forms.py
+++ b/project/accounts/forms.py
@@ -3,7 +3,7 @@
 from django import forms
 from django.forms.models import ModelForm
 from django.contrib.auth import get_user_model
-from django.utils.translation import ugettext_lazy as _
+from django.utils.translation import gettext_lazy as _
 from .reserved_usernames import RESERVED_USERNAMES
 from accounts.models import Profile
 
diff --git a/project/core/urls.py b/project/core/urls.py
--- a/project/core/urls.py
+++ b/project/core/urls.py
@@ -17,9 +17,8 @@
 from django.conf import settings
 from django.conf.urls.static import static
 from django.contrib import admin
-from django.urls import include, path
+from django.urls import include, path, re_path
 from django.views.generic.base import RedirectView
-from django.conf.urls import url
 from django.views.static import serve
 
 from core.router import CiviWikiRouter
@@ -49,7 +48,7 @@
         "mstile-144x144.png",
         RedirectView.as_view(url="/static/favicon/mstile-144x144.png"),
     ),
-    url(r"^media/(?P<path>.*)$", serve, {"document_root": settings.MEDIA_ROOT}),
+    re_path(r"^media/(?P<path>.*)$", serve, {"document_root": settings.MEDIA_ROOT}),
 ]
 
 urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
diff --git a/project/threads/migrations/0006_alter_civi_linked_civis.py b/project/threads/migrations/0006_alter_civi_linked_civis.py
new file mode 100644
--- /dev/null
+++ b/project/threads/migrations/0006_alter_civi_linked_civis.py
@@ -0,0 +1,18 @@
+# Generated by Django 4.0.1 on 2022-01-31 08:48
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('threads', '0005_auto_20211030_1148'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='civi',
+            name='linked_civis',
+            field=models.ManyToManyField(blank=True, related_name='links', to='threads.Civi'),
+        ),
+    ]


Test patch:
diff --git a/project/accounts/tests/test_views.py b/project/accounts/tests/test_views.py
--- a/project/accounts/tests/test_views.py
+++ b/project/accounts/tests/test_views.py
@@ -35,7 +35,7 @@ def test_login_url_matches_with_login_view(self):
         """Whether login URL matches with the correct view"""
 
         view = resolve("/login/")
-        self.assertEqual(view.func.__name__, auth_views.LoginView.__name__)
+        self.assertEqual(view.func.view_class, auth_views.LoginView)
 
     def test_the_user_with_the_correct_credentials_login(self):
         """Whether a user with the correct credentials can login"""
@@ -77,7 +77,7 @@ def test_register_url_matches_with_register_view(self):
         """Whether register URL matches with the correct view"""
 
         view = resolve("/register/")
-        self.assertEqual(view.func.__name__, RegisterView.__name__)
+        self.assertEqual(view.func.view_class, RegisterView)
 
     def test_register_view_creates_a_user_successfully(self):
         """Whether register view creates a new user with success"""