Repository: DDMAL/CantusDB

Issue:
move CustomLogoutView out of views.py
c:

views.py should only be for functional views


Discussion:

Resolving patch:
diff --git a/django/cantusdb_project/main_app/urls.py b/django/cantusdb_project/main_app/urls.py
--- a/django/cantusdb_project/main_app/urls.py
+++ b/django/cantusdb_project/main_app/urls.py
@@ -4,7 +4,7 @@
 from main_app.views.source import SourceCreateView, SourceEditView
 from main_app.views.chant import ChantEditVolpianoView
 from django.contrib.auth import views as auth_views
-from main_app.views.user import UserDetailView, UserSourceListView
+from main_app.views.user import UserDetailView, UserSourceListView, CustomLogoutView
 
 urlpatterns = [
     # static pages
@@ -12,7 +12,7 @@
     path("contact/", views.contact_us, name="contact"),
     # login/logout/user
     path('login/', auth_views.LoginView.as_view(redirect_authenticated_user=True), name="login"),
-    path('logout/', views.CustomLogoutView.as_view(), name="logout"),
+    path('logout/', CustomLogoutView.as_view(), name="logout"),
     path("my-sources/", UserSourceListView.as_view(), name="my-sources"),
     path("users/<int:user_id>", UserDetailView.as_view(), name="user-detail"),
 
diff --git a/django/cantusdb_project/main_app/views/user.py b/django/cantusdb_project/main_app/views/user.py
--- a/django/cantusdb_project/main_app/views/user.py
+++ b/django/cantusdb_project/main_app/views/user.py
@@ -6,6 +6,8 @@
 from django.contrib.auth.mixins import LoginRequiredMixin
 from django.db.models import Q
 from django.core.paginator import Paginator
+from django.contrib.auth.views import LogoutView
+from django.contrib import messages
 
 class UserDetailView(DetailView):
     """Detail view for User model
@@ -44,4 +46,13 @@ def get_context_data(self, **kwargs):
         page_obj = paginator.get_page(page_number)
 
         context["user_created_sources_page_obj"] = page_obj
-        return context
\ No newline at end of file
+        return context
+
+class CustomLogoutView(LogoutView):
+    def get_next_page(self):
+        next_page = super().get_next_page()
+        messages.success(
+            self.request, 
+            'You have successfully logged out!'
+        )
+        return next_page
diff --git a/django/cantusdb_project/main_app/views/views.py b/django/cantusdb_project/main_app/views/views.py
--- a/django/cantusdb_project/main_app/views/views.py
+++ b/django/cantusdb_project/main_app/views/views.py
@@ -11,8 +11,6 @@
 )
 from main_app.forms import ContactForm
 from django.core.mail import send_mail, get_connection
-from django.contrib.auth.views import LogoutView
-from django.contrib import messages
 from django.contrib.auth.decorators import login_required
 from next_chants import next_chants
 
@@ -524,14 +522,6 @@ def json_nextchants(request, cantus_id):
     suggested_chants_dict = {cantus_id: count for (cantus_id, count) in ids_and_counts}
     return JsonResponse(suggested_chants_dict)
     
-class CustomLogoutView(LogoutView):
-    def get_next_page(self):
-        next_page = super().get_next_page()
-        messages.success(
-            self.request, 
-            'You have successfully logged out!'
-        )
-        return next_page
 
 def handle404(request, exception):
     return render(request, "404.html")


Test patch: