Skip to content

Commit

Permalink
Show occurrence source in PDF checklist if not gbif data (#4211)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimasciput authored Sep 2, 2024
1 parent 9588e5f commit e89310c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bims/api_views/checklist.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def generate_pdf_checklist(download_request, module_name, collection_records, ba
Paragraph(taxon['sources'], getSampleStyleSheet()['Normal'])
]

if common_name:
if common_name != '':
if common_name not in common_names_and_count:
common_names_and_count[common_name] = (taxon['occurrence_records'], len(all_taxa))
all_taxa.append(taxon_entry)
Expand Down
22 changes: 19 additions & 3 deletions bims/serializers/checklist_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,30 @@ def get_sources(self, obj: Taxonomy):
bio = self.get_bio_data(obj)
if not bio.exists():
return ''
sources = []
if bio.filter(source_collection__iexact='gbif').exists():
dataset_names = list(bio.values_list(
'additional_data__datasetName',
flat=True
))
dataset_names = [name for name in dataset_names if name is not None]
if dataset_names:
return ', '.join(set(dataset_names))
sources = [name for name in dataset_names if name is not None]
bio = bio.distinct('source_reference')
try:
for collection in bio:
try:
if (
collection.source_reference and
str(collection.source_reference) != 'Global Biodiversity Information Facility (GBIF)'
):
sources.append(
str(collection.source_reference)
)
except ContentType.DoesNotExist:
continue
except TypeError:
pass
if sources:
return ', '.join(set(sources))
return '-'

class Meta:
Expand Down

0 comments on commit e89310c

Please sign in to comment.