SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit e45813b8 authored by Boris Ponsioen's avatar Boris Ponsioen
Browse files

Adds truncate_list template tag for long author lists in citables

parent fbd099e7
No related branches found
No related tags found
No related merge requests found
......@@ -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']
......
{% 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 %}
......
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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment