SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit c3d52257 authored by Jean-Sébastien Caux's avatar Jean-Sébastien Caux
Browse files

Improve display in case pubfractions are zero

parent ed30e1f7
No related branches found
No related tags found
No related merge requests found
...@@ -127,25 +127,22 @@ class Organization(models.Model): ...@@ -127,25 +127,22 @@ class Organization(models.Model):
def pubfraction_for_publication(self, doi_label): def pubfraction_for_publication(self, doi_label):
""" """
Return the organization's pubfraction for this publication, or the string 'Not defined'. Return the organization's pubfraction for a publication.
""" """
pfs = OrgPubFraction.objects.filter(publication__doi_label=doi_label) pfs = OrgPubFraction.objects.filter(publication__doi_label=doi_label)
try: try:
return pfs.get(organization=self).fraction return pfs.get(organization=self).fraction
except OrgPubFraction.DoesNotExist: except OrgPubFraction.DoesNotExist:
# check if any children have a nonzero contribution
children_ids = [k['id'] for k in list(self.children.all().values('id'))] children_ids = [k['id'] for k in list(self.children.all().values('id'))]
children_contribs = pfs.filter(organization__id__in=children_ids).aggregate( children_contribs = pfs.filter(organization__id__in=children_ids).aggregate(
Sum('fraction'))['fraction__sum'] Sum('fraction'))['fraction__sum']
if children_contribs: if children_contribs is not None:
if children_contribs > 0: message = "as parent (ascribed to "
message = "as parent (ascribed to " for child in self.children.all():
for child in self.children.all(): pfc = child.pubfraction_for_publication(doi_label)
pfc = child.pubfraction_for_publication(doi_label) if pfc not in ['No PubFraction ascribed', 'Not yet defined']:
if pfc not in ['No PubFraction ascribed', 'Not yet defined']: message += "%s: %s; " % (child, pfc)
message += "%s: %s; " % (child, pfc) return message.rpartition(';')[0] + ')'
return message.rpartition(';')[0] + ')'
return 'No PubFraction ascribed'
return 'Not yet defined' return 'Not yet defined'
def pubfractions_in_year(self, year): def pubfractions_in_year(self, year):
......
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