Repository: DDMAL/CantusDB

Issue:
"sources created by user" not present on homepage
In investigating #644 I noticed that NewCantus does not have the additional list of "sources created by user" that OldCantus has below the "My sources" list on the landing page. This is probably only really relevant to people creating a lot of sources (me), but it is a change from OldCantus for people used to looking in a particular spot for their work.

[What would be nicer, really, would be to have "sources created by me" in one list, and "sources assigned to me" (as a proofreader, as a contributor, etc.) in another list. But replication before innovation!]


Discussion:
I don't think we've made any effort to implement this (and it hasn't been on my radar at all, probably because I never created any sources back when I worked as an RA for CD!)

We may need to sort out #237 first...

Resolving patch:
diff --git a/django/cantusdb_project/main_app/models/source.py b/django/cantusdb_project/main_app/models/source.py
--- a/django/cantusdb_project/main_app/models/source.py
+++ b/django/cantusdb_project/main_app/models/source.py
@@ -75,6 +75,10 @@ class Source(BaseModel):
         get_user_model(), related_name="sources_user_can_edit", blank=True
     )
 
+    ######
+    # The following five fields have nothing to do with user permissions,
+    # instead they give credit to users who are indexers and are displayed
+    # on the user detail page as sources the user has contributed to.
     inventoried_by = models.ManyToManyField(
         get_user_model(), related_name="inventoried_sources", blank=True
     )
@@ -90,6 +94,7 @@ class Source(BaseModel):
     other_editors = models.ManyToManyField(
         get_user_model(), related_name="edited_sources", blank=True
     )
+    ######
 
     segment = models.ForeignKey(
         "Segment", on_delete=models.PROTECT, blank=True, null=True
diff --git a/django/cantusdb_project/main_app/templatetags/helper_tags.py b/django/cantusdb_project/main_app/templatetags/helper_tags.py
--- a/django/cantusdb_project/main_app/templatetags/helper_tags.py
+++ b/django/cantusdb_project/main_app/templatetags/helper_tags.py
@@ -5,6 +5,8 @@
 from articles.models import Article
 from django.utils.safestring import mark_safe
 from django.urls import reverse
+from django.core.paginator import Paginator
+
 
 register = template.Library()
 
@@ -187,3 +189,16 @@ def has_group(user, group_name):
         templates/base.html
     """
     return user.groups.filter(name=group_name).exists()
+
+
+@register.simple_tag(takes_context=True)
+def get_user_source_pagination(context):
+    user_created_sources = (
+        Source.objects.filter(created_by=context["user"])
+        .order_by("-date_created")
+        .distinct()
+    )
+    paginator = Paginator(user_created_sources, 10)
+    page_number = context["request"].GET.get("page")
+    page_obj = paginator.get_page(page_number)
+    return page_obj
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
@@ -662,7 +662,7 @@ def redirect_node_url(request, pk: int) -> HttpResponse:
     if get_user_id_from_old_indexer_id(pk) is not None:
         return redirect("user-detail", user_id)
 
-    for (rec_type, view) in possible_types:
+    for rec_type, view in possible_types:
         if record_exists(rec_type, pk):
             # if an object is found, a redirect() call to the appropriate view is returned
             return redirect(view, pk)


Test patch: