Repository: DDMAL/CantusDB

Issue:
"My sources" panel should appear on homepage
In OldCantus on the homepage when a user is logged in, a list of sources appears in a "My sources" box in the left sidebar. This box replaces the "jump to source" and "what's new" boxes that are visible when a user is not logged in.

In NewCantus, the "jump to source" and "what's new" boxes appear whether or not a user is logged in. Behavior on NewCantus should be changed to match that of OldCantus


Discussion:
When I log into old Cantus, I am able to see both "jump to source" and "sources created by user" in addition to "my sources".

Perhaps this is another instance of seeing different things based on the given privilege?
I see "jump to source", "my sources", "sources created by user". 

Looks like "my sources" and "sources created by user" replace "what's new" upon logging in.

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
@@ -5,6 +5,7 @@
 from main_app.models import Source
 from articles.models import Article
 from django.utils.safestring import mark_safe
+from django.urls import reverse
 
 register = template.Library()
 
@@ -27,6 +28,57 @@ def recent_articles():
     return mark_safe(recent_articles_string)
 
 
+@register.simple_tag(takes_context=False)
+def my_sources(user):
+    def make_source_detail_link_with_siglum(source):
+        id = source.id
+        siglum = source.rism_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-volpiano", 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)
+        edit_chants_link = make_edit_chants_link(source)
+        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]]:
     """Converts month number to textual representation, 3 letters (Jan, Mar, etc)"""


Test patch: