Repository: DDMAL/CantusDB

Issue:
"My sources" is weird
On both staging and production, the My Sources sidebar doesn't show very many sources at all. I only see 6, but there are actually dozns assigned to me; and I don't see the sources I've created at all (the sidebar for this only  shows up within http://206.12.93.196/my-sources/, not on the home page, and it's empty.)

The displayed name is also weird--it should be the whole manuscript siglum, not just the library siglum. see New and Old below.

![image](https://user-images.githubusercontent.com/67451875/204893178-b4175024-1d1d-465d-97ea-bf2c1faad2c5.png)
![image](https://user-images.githubusercontent.com/67451875/204893254-7709a59a-ab2b-4e3c-adb5-82d6a28473b8.png)



Discussion:
> The displayed name is also weird--it should be the whole manuscript siglum, not just the library siglum.

Can you check the sources' `rism_siglum`s? In each place where you're seeing `D-TRs`, the page is displaying the source's `rism_siglum`, so I think this could be a data issue.

That said, each source has a `siglum` field that is separate from its `rism_siglum` field, and often includes additional information (see [Source Model](https://github.com/DDMAL/CantusDB/wiki/Source-Model#fields) in the Wiki). Maybe we should be using the `siglum` field here rather than `rism_siglum`?
> That said, each source has a `siglum` field that is separate from its `rism_siglum` field, and often includes additional information (see [Source Model](https://github.com/DDMAL/CantusDB/wiki/Source-Model#fields) in the Wiki). Maybe we should be using the `siglum` field here rather than `rism_siglum`?

Yes, I think this should be the `siglum` field.  (`rism_siglum` may be empty for some sources, but `siglum` should never be; plus it is more informative when there are many sources from the same library.)


Question: can part of this be explained by what's going on with [adding users to sources](https://github.com/DDMAL/CantusDB/issues/450#issuecomment-1357932581) - i.e. you're an indexer, and you have sources associated with you as an indexer, but those aren't necessarily the right relations for changing your permissions for sources as a user?
Also, I can find you in the indexer list on [production](http://206.12.93.196/indexers/) but not on [staging](http://206.12.88.113/indexers/)... I'm not sure how concerned to be about this.
This sidebar still doesn't use siglum (although this was fixed elsewhere--see #643). This should be easy to fix. 

Figuring out how which sources are displayed here should be dealt with eventually, but I suppose we can keep it low priority since the problem only affects a few high-frequency Cantus users.
the PR I just opened fixes how these sources are displayed (i.e. siglum vs rism_siglum). @lucasmarchd01, when you get a chance, please look into what's going on with which sources are displayed here.

Resolving patch:
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
@@ -6,6 +6,7 @@
 from django.utils.safestring import mark_safe
 from django.urls import reverse
 from django.core.paginator import Paginator
+from django.db.models import Q
 
 
 register = template.Library()
@@ -34,73 +35,6 @@ def recent_articles():
     return mark_safe(recent_articles_string)
 
 
-@register.simple_tag(takes_context=False)
-def my_sources(user):
-    """
-    Generates a html unordered list of sources the currently logged-in user has access to edit, for display on the homepage
-
-    Used in:
-        templates/flatpages/default.html
-    """
-
-    def make_source_detail_link_with_siglum(source):
-        id = source.id
-        siglum = source.siglum
-        url = reverse("source-detail", args=[id])
-        link = '<a href="{}">{}</a>'.format(url, siglum)
-        return link
-
-    def make_source_detail_link_with_title(source):
-        id = source.id
-        title = source.title
-        url = reverse("source-detail", args=[id])
-        link = '<a href="{}">{}</a>'.format(url, title)
-        return link
-
-    def make_add_new_chants_link(source):
-        id = source.id
-        url = reverse("chant-create", args=[id])
-        link = '<a href="{}">+ Add new chant</a>'.format(url)
-        return link
-
-    def make_edit_chants_link(source):
-        id = source.id
-        url = reverse("source-edit-chants", args=[id])
-        link = '<a href="{}">Edit chants (Fulltext & Volpiano editor)</a>'.format(url)
-        return link
-
-    def make_links_for_source(source):
-        link_with_siglum = make_source_detail_link_with_siglum(source)
-        link_with_title = make_source_detail_link_with_title(source)
-        add_new_chants_link = make_add_new_chants_link(source)
-        if source.chant_set.exists():
-            edit_chants_link = make_edit_chants_link(source)
-        else:
-            edit_chants_link = ""
-        template = """{sigl}<br>
-        <small>
-            <b>{title}</b><br>
-            {add}<br>
-            {edit}<br>
-        </small>
-        """
-        links_string = template.format(
-            sigl=link_with_siglum,
-            title=link_with_title,
-            add=add_new_chants_link,
-            edit=edit_chants_link,
-        )
-        return links_string
-
-    MAX_SOURCES_TO_DISPLAY = 6
-    sources = list(user.sources_user_can_edit.all())[:MAX_SOURCES_TO_DISPLAY]
-    source_links = [make_links_for_source(source) for source in sources]
-    list_items = ["<li>{}</li>".format(link) for link in source_links]
-    joined_list_items = "".join(list_items)
-    links_ul = "<ul>{}</ul>".format(joined_list_items)
-    return mark_safe(links_ul)
-
-
 @register.filter(name="month_to_string")
 def month_to_string(value: Optional[Union[str, int]]) -> Optional[Union[str, int]]:
     """
@@ -197,11 +131,26 @@ def has_group(user, group_name):
 @register.simple_tag(takes_context=True)
 def get_user_source_pagination(context):
     user_created_sources = (
-        Source.objects.filter(created_by=context["user"])
+        Source.objects.filter(
+            Q(current_editors=context["user"]) | Q(created_by=context["user"])
+        )
         .order_by("-date_created")
         .distinct()
     )
-    paginator = Paginator(user_created_sources, 10)
+    paginator = Paginator(user_created_sources, 6)
     page_number = context["request"].GET.get("page")
-    page_obj = paginator.get_page(page_number)
-    return page_obj
+    user_sources_page_obj = paginator.get_page(page_number)
+    return user_sources_page_obj
+
+
+@register.simple_tag(takes_context=True)
+def get_user_created_source_pagination(context):
+    user_created_sources = (
+        Source.objects.filter(created_by=context["user"])
+        .order_by("-date_created")
+        .distinct()
+    )
+    paginator = Paginator(user_created_sources, 6)
+    page_number = context["request"].GET.get("page2")
+    user_created_sources_page_obj = paginator.get_page(page_number)
+    return user_created_sources_page_obj


Test patch: