Skip to content

Commit 181546c

Browse files
Truncate long author lists on front page cards (fixes #2462)
1 parent 7a5ab9f commit 181546c

File tree

4 files changed

+93
-4
lines changed

4 files changed

+93
-4
lines changed

physionet-django/project/fixtures/demo-project.json

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,74 @@
495495
"project": 20
496496
}
497497
},
498+
{
499+
"model": "project.publishedauthor",
500+
"pk": 9,
501+
"fields": {
502+
"user": [
503+
"george"
504+
],
505+
"display_order": 2,
506+
"is_submitting": false,
507+
"is_corresponding": false,
508+
"approval_datetime": "2018-11-14T21:11:11.781Z",
509+
"first_names": "George",
510+
"last_name": "Moody",
511+
"corresponding_email": "[email protected]",
512+
"project": 1
513+
}
514+
},
515+
{
516+
"model": "project.publishedauthor",
517+
"pk": 10,
518+
"fields": {
519+
"user": [
520+
"aewj"
521+
],
522+
"display_order": 3,
523+
"is_submitting": false,
524+
"is_corresponding": false,
525+
"approval_datetime": "2018-11-14T21:11:11.781Z",
526+
"first_names": "Alistair",
527+
"last_name": "Johnson",
528+
"corresponding_email": "[email protected]",
529+
"project": 1
530+
}
531+
},
532+
{
533+
"model": "project.publishedauthor",
534+
"pk": 11,
535+
"fields": {
536+
"user": [
537+
"admin"
538+
],
539+
"display_order": 4,
540+
"is_submitting": false,
541+
"is_corresponding": false,
542+
"approval_datetime": "2018-11-14T21:11:11.781Z",
543+
"first_names": "Admin",
544+
"last_name": "Bot",
545+
"corresponding_email": "[email protected]",
546+
"project": 1
547+
}
548+
},
549+
{
550+
"model": "project.publishedauthor",
551+
"pk": 12,
552+
"fields": {
553+
"user": [
554+
"jameslawson"
555+
],
556+
"display_order": 5,
557+
"is_submitting": false,
558+
"is_corresponding": false,
559+
"approval_datetime": "2018-11-14T21:11:11.781Z",
560+
"first_names": "James",
561+
"last_name": "Lawson",
562+
"corresponding_email": "[email protected]",
563+
"project": 1
564+
}
565+
},
498566
{
499567
"model": "project.topic",
500568
"pk": 1,

physionet-django/project/templatetags/project_templatetags.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,18 @@ def call_method(obj, method_name, *args):
212212
@register.simple_tag(name='can_view_project_files')
213213
def can_view_project_files(project, user, request=None):
214214
return can_view_project_files_func(project, user, request)
215+
216+
217+
@register.filter(name='truncate_authors')
218+
def truncate_authors(author_list, max_authors=5):
219+
"""
220+
Truncate a list of authors to max_authors, appending 'et al' if truncated.
221+
222+
Usage: {{ published_project.author_list|truncate_authors:5 }}
223+
"""
224+
authors = list(author_list)
225+
if len(authors) <= max_authors:
226+
return ', '.join(author.get_full_name() for author in authors)
227+
else:
228+
truncated = ', '.join(author.get_full_name() for author in authors[:max_authors])
229+
return truncated + ', et al.'

physionet-django/search/templates/search/homepage_content_list.html

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ <h3 class="card-title">
1212
</a>
1313
</h3>
1414
{% if not published_project.is_legacy %}
15-
<p>
16-
{% for author in published_project.author_list %}
17-
{{ author.get_full_name }}{% if not forloop.last %}, {% endif %}
18-
{% endfor %}
15+
<p class="card-authors">
16+
{{ published_project.author_list|truncate_authors:3 }}
1917
</p>
2018
{% endif %}
2119

physionet-django/static/custom/css/style.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,14 @@ body .main {
240240
overflow: hidden;
241241
color: var(--gray-color);
242242
}
243+
.modern-ui .card-authors {
244+
font-size: 0.875rem;
245+
color: var(--gray-color);
246+
display: -webkit-box;
247+
-webkit-line-clamp: 2;
248+
-webkit-box-orient: vertical;
249+
overflow: hidden;
250+
}
243251
.modern-ui .badge-dark {
244252
background-color: var(--gray-200);
245253
color: var(--secondary-color);

0 commit comments

Comments
 (0)