diff --git a/metacore/models.py b/metacore/models.py index fd8962ba432efab07d5acca289c96dd751f29ad8..84354e4e6f38bdeb11692591ff14def335ec030b 100644 --- a/metacore/models.py +++ b/metacore/models.py @@ -54,8 +54,11 @@ class Citable(DynamicDocument): def times_cited(self): return [] - def author_list(self): - return '; '.join(self.authors) + def author_list(self, max_n=None): + if max_n and max_n < len(self.authors): + return '; '.join(self.authors[:max_n]) + ' et al.' + else: + return '; '.join(self.authors) def crossref_ref_count(self): return self.metadata['is-referenced-by-count'] diff --git a/metacore/templates/partials/citable_card_content.html b/metacore/templates/partials/citable_card_content.html index a704cc518f562247491e0df4070fa1215e16b550..3f69c07b4904c9c96357d73f0469f48797fb7160 100644 --- a/metacore/templates/partials/citable_card_content.html +++ b/metacore/templates/partials/citable_card_content.html @@ -1,9 +1,11 @@ +{% 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.author_list }}</p> + <p class="mb-3 author_list">by {{ citable.authors|truncate_list:10 }}</p> </div> {% block card_footer %} diff --git a/metacore/templatetags/__init__.py b/metacore/templatetags/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/metacore/templatetags/metacore_extras.py b/metacore/templatetags/metacore_extras.py new file mode 100644 index 0000000000000000000000000000000000000000..3235b2c2db23a7cc8c60747ed7f4a5ee15f4dbbe --- /dev/null +++ b/metacore/templatetags/metacore_extras.py @@ -0,0 +1,11 @@ +from django import template + +register = template.Library() + +@register.filter +def truncate_list(authors, max_n): + """ Returns author list, 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)