diff --git a/journals/models.py b/journals/models.py index 07de757148e47caa0a7ad8d2670b41c7cfb5d628..0b3785c2de4c36f79f9b9318a99efc51e4ef3051 100644 --- a/journals/models.py +++ b/journals/models.py @@ -7,7 +7,7 @@ from django.contrib.contenttypes.models import ContentType from django.contrib.postgres.fields import JSONField from django.core.exceptions import ValidationError from django.db import models -from django.db.models import Avg, Sum, F +from django.db.models import Avg, Min, Sum, F from django.utils import timezone from django.urls import reverse @@ -499,7 +499,8 @@ class Publication(models.Model): """ from organizations.models import Organization return Organization.objects.filter( - publicationauthorstable__publication=self).distinct() + publicationauthorstable__publication=self + ).annotate(order=Min('publicationauthorstable__order')).order_by('order') def get_all_funders(self): from funders.models import Funder diff --git a/journals/templates/journals/publication_detail.html b/journals/templates/journals/publication_detail.html index f56a01ef24b4c783cb564887ff1209ad89fe3a65..18192bad57160fcc94d6c5124733994b7dbd30c3 100644 --- a/journals/templates/journals/publication_detail.html +++ b/journals/templates/journals/publication_detail.html @@ -96,49 +96,49 @@ <hr/> <div class="row"> <div class="col-12"> - <h4>Author{{ publication.authors.all|length|pluralize }} and Organization{{ affiliations_list|length|pluralize }} links</h4> - <ul class="list-inline"> - {% for author in publication.authors.all %} - <li class="list-inline-item"> - {% for aff in affiliations_list %} - {% if aff in author.affiliations.all %} - <sup>{{ forloop.counter }} </sup> - {% endif %}{% endfor %} - {% if author.is_registered %} - <a href="{{ author.contributor.get_absolute_url }}">{{ author.contributor.user.first_name }} {{ author.contributor.user.last_name }}</a> - {% else %} - {{ author.unregistered_author.first_name }} {{ author.unregistered_author.last_name }} - {% endif %} - </li> - {% if not forloop.last %}, {% endif %} - {% endfor %} - </ul> - - <ul class="list list-unstyled"> + <h4>Author{{ publication.authors.all|length|pluralize }} and Organization{{ affiliations_list|length|pluralize }} links</h4> + <ul class="list-inline"> + {% for author in publication.authors.all %} + <li class="list-inline-item"> {% for aff in affiliations_list %} - <li><sup>{{ forloop.counter }}</sup> <a href="{{ aff.get_absolute_url }}">{{ aff.name_full }}</a></li> - {% endfor %} - </ul> - - {% if publication.get_all_funders %} - <h4>Funder{{ publication.get_all_funders|length|pluralize }} for the research work leading to this publication</h4> - <ul> - {% for funder in publication.get_all_funders %} - <li><a href="{{ funder.get_absolute_url }}">{{ funder }}</a></li> - {% endfor %} - </ul> - {% endif %} - - {% if is_scipost_admin or is_edcol_admin %} - {% if publication.institutions.all %} - <h4>Institution{{ publication.institutions.all|pluralize }} related to this Publication (<span class="text-danger">Admin-only view, to be removed</span>)</h4> - <ul> - {% for institution in publication.institutions.all %} - <li><a href="{{ institution.get_absolute_url }}">{{ institution }}</a></li> - {% endfor %} - </ul> - {% endif %} - {% endif %} + {% if aff in author.affiliations.all %} + <sup>{{ forloop.counter }} </sup> + {% endif %}{% endfor %} + {% if author.is_registered %} + <a href="{{ author.contributor.get_absolute_url }}">{{ author.contributor.user.first_name }} {{ author.contributor.user.last_name }}</a> + {% else %} + {{ author.unregistered_author.first_name }} {{ author.unregistered_author.last_name }} + {% endif %} + </li> + {% if not forloop.last %}, {% endif %} + {% endfor %} + </ul> + + <ul class="list list-unstyled"> + {% for aff in affiliations_list %} + <li><sup>{{ forloop.counter }}</sup> <a href="{{ aff.get_absolute_url }}">{{ aff.name_full }}</a></li> + {% endfor %} + </ul> + + {% if publication.get_all_funders %} + <h4>Funder{{ publication.get_all_funders|length|pluralize }} for the research work leading to this publication</h4> + <ul> + {% for funder in publication.get_all_funders %} + <li><a href="{{ funder.get_absolute_url }}">{{ funder }}</a></li> + {% endfor %} + </ul> + {% endif %} + + {% if is_scipost_admin or is_edcol_admin %} + {% if publication.institutions.all %} + <h4>Institution{{ publication.institutions.all|pluralize }} related to this Publication (<span class="text-danger">Admin-only view, to be removed</span>)</h4> + <ul> + {% for institution in publication.institutions.all %} + <li><a href="{{ institution.get_absolute_url }}">{{ institution }}</a></li> + {% endfor %} + </ul> + {% endif %} + {% endif %} </div> </div>