Skip to content

Commit

Permalink
SubSpecies should not be full taxon name in csv download (#4222)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimasciput authored Sep 4, 2024
1 parent 2464abd commit 50d0c2b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
23 changes: 17 additions & 6 deletions bims/serializers/bio_collection_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,12 +412,6 @@ def get_genus(self, obj):
'genus_name'
)

def get_sub_species(self, obj: BiologicalCollectionRecord):
return self.taxon_name_by_rank(
obj,
'sub_species_name'
)

def get_species(self, obj):
species_name = self.taxon_name_by_rank(
obj,
Expand All @@ -433,6 +427,23 @@ def get_species(self, obj):
return species_name.strip()
return '-'

def get_sub_species(self, obj: BiologicalCollectionRecord):
sub_species_name = self.taxon_name_by_rank(
obj,
'sub_species_name'
)
if sub_species_name:
genus = self.get_genus(obj)
if genus:
sub_species_name = sub_species_name.replace(genus, '', 1)

species = self.get_species(obj)
if species:
sub_species_name = sub_species_name.replace(species, '', 1)

return sub_species_name.strip()
return '-'

def get_kingdom(self, obj):
return self.taxon_name_by_rank(
obj,
Expand Down
14 changes: 11 additions & 3 deletions bims/views/download_csv_taxa_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ def get_species(self, obj: Taxonomy):
return species_name.strip()
return species_name

def get_sub_species(self, obj: Taxonomy):
sub_species_name = obj.sub_species_name
if sub_species_name:
genus_name = obj.genus_name
if genus_name:
sub_species_name = sub_species_name.replace(genus_name, '', 1)
species_name = obj.species_name
if species_name:
sub_species_name = sub_species_name.replace(species_name, '', 1)
return sub_species_name

def get_taxon(self, obj):
return obj.canonical_name

Expand Down Expand Up @@ -140,9 +151,6 @@ def get_gbif_link(self, obj):
)
return '-'

def get_sub_species(self, obj: Taxonomy):
return obj.sub_species_name

class Meta:
model = Taxonomy
fields = (
Expand Down

0 comments on commit 50d0c2b

Please sign in to comment.