Skip to content

Commit 24ebf51

Browse files
authored
Fix missing authors in source reference (#4421)
* Fix missing authors in source reference * Fix source reference test
1 parent 059c374 commit 24ebf51

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

bims/models/source_reference.py

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -311,35 +311,27 @@ def author_list(self):
311311
for author in authors:
312312
if author.user:
313313
users.append(author.user)
314-
else:
314+
elif author:
315315
author.save()
316-
users.append(author.user)
316+
if author.user:
317+
users.append(author.user)
317318
authors = users
318319
if self.document:
319320
try:
320321
bims_document = BimsDocument.objects.get(
321322
document__id=self.document.id
322323
)
323-
if bims_document.authors.all().exists():
324-
_authors = bims_document.authors.all()
325-
different = False
326-
if _authors.count() != len(authors):
327-
authors = _authors
328-
different = True
329-
if not different:
330-
for _author in authors:
331-
if _author not in authors:
332-
different = True
333-
break
334-
if different:
335-
authors = _authors
324+
bims_authors = list(bims_document.authors.all())
325+
if bims_authors:
326+
if len(bims_authors) != len(authors) or any(a not in authors for a in bims_authors):
327+
authors = bims_authors
336328
except BimsDocument.DoesNotExist:
337329
pass
338330
return authors
339331

340332
@property
341333
def authors(self):
342-
authors_name = format_authors(self.author_list)
334+
authors_name = format_authors(self.author_list).strip()
343335
return authors_name if authors_name else '-'
344336

345337
@property
@@ -490,12 +482,12 @@ def author_list(self):
490482
return users
491483
except BimsDocument.DoesNotExist:
492484
pass
493-
return [self.source.owner]
485+
return [self.source.owner] if self.source.owner else []
494486

495487
@property
496488
def authors(self):
497-
return '-'
498-
return format_authors(self.author_list)
489+
authors_string = format_authors(self.author_list)
490+
return authors_string if authors_string else '-'
499491

500492
def link_template(self):
501493
"""Returns html template containing the reference data"""

0 commit comments

Comments
 (0)