From 66dc1cae15bbf4bbd1892c3d67d0ca11a6804d0f Mon Sep 17 00:00:00 2001
From: Jorran de Wit <jorrandewit@outlook.com>
Date: Mon, 29 Oct 2018 05:20:49 +0000
Subject: [PATCH] Alter displaying for citations

---
 .../templates/partials/citable_card_content.html   | 14 ++++++++------
 metacore/templatetags/metacore_extras.py           | 11 ++++++-----
 2 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/metacore/templates/partials/citable_card_content.html b/metacore/templates/partials/citable_card_content.html
index 56d1f003f..05c2e4e85 100644
--- a/metacore/templates/partials/citable_card_content.html
+++ b/metacore/templates/partials/citable_card_content.html
@@ -2,15 +2,17 @@
 {% load metacore_extras %}
 
 <div class="submission_title">
-    <!-- <h5 class="pb-0 subject_area">{{ submission.get_subject_area_display }}</h5> -->
-    <h3 class="card-title mb-0 submisssion_title">
-        {{ citable.title }}
-    </h3>
-    <p class="mb-3 author_list">by {{ citable.authors|truncate_list:10 }}</p>
+    <h3 class="card-title mb-0 submisssion_title">{{ citable.title }}</h3>
+    <div class="author_list mb-0">by {{ citable.authors|join_authors_list:16 }}
+        {% if citable.authors|length > 16 %}
+            &middot; <a href="javascript:;" data-toggle="toggle" data-target="#authors-{{ citable.id }}">See all authors</a>
+            <div style="display: none;" id="authors-{{ citable.id }}" class="py-2">{{ citable.authors|join_authors_list }}</div>
+        {% endif %}
+    </div>
 </div>
 
 {% block card_footer %}
-    <p class="text-muted mb-0">
+    <p class="text-muted mb-0 mt-3">
     Cited {{ citable.crossref_ref_count|intcomma }} times (CrossRef) / {{ citable.times_cited|intcomma }} times (SciPost Meta)
         &middot; doi: <a href="//doi.org/{{ citable.doi }}" target="_blank">{{ citable.doi }}</a>
       <br>
diff --git a/metacore/templatetags/metacore_extras.py b/metacore/templatetags/metacore_extras.py
index 2582c6fec..56b45b0b4 100644
--- a/metacore/templatetags/metacore_extras.py
+++ b/metacore/templatetags/metacore_extras.py
@@ -8,9 +8,10 @@ register = template.Library()
 
 
 @register.filter
-def truncate_list(authors, max_n):
-    """ Returns author list, truncated to max_n authors when the list is longer """
+def join_authors_list(authors, max_n=None):
+    """ Returns authors list as string, truncated to max_n authors when the list is longer."""
     if max_n and max_n < len(authors):
-        return '; '.join(authors[:max_n]) + ' et al.'
-    else:
-        return '; '.join(authors)
+        return ', '.join(authors[:max_n - 1]) + ' ... ' + authors[-1]
+    elif len(authors) > 1:
+        return ', '.join(authors[:-1]) + ' and ' + authors[-1]
+    return authors[0]
-- 
GitLab