diff --git a/bims/api_views/taxon.py b/bims/api_views/taxon.py index 4d781fc9b..c611a973f 100644 --- a/bims/api_views/taxon.py +++ b/bims/api_views/taxon.py @@ -5,6 +5,7 @@ from django.contrib.auth import get_user_model from django.db import transaction, IntegrityError +from django.forms import model_to_dict from django.http import Http404 from django.db.models import Count, Case, Value, When, F, CharField, Prefetch, Q from django.contrib.auth.mixins import LoginRequiredMixin @@ -358,20 +359,34 @@ def post(self, request, *args): taxonomy.save() with transaction.atomic(): - TaxonomyUpdateProposal.objects.get_or_create( - original_taxonomy=taxonomy, - taxon_group=taxon_group, - status='pending', - new_data=True, - scientific_name=taxonomy.scientific_name, - canonical_name=taxonomy.canonical_name, - rank=taxonomy.rank, - parent=taxonomy.parent, - taxonomic_status=taxonomy.taxonomic_status, - legacy_canonical_name=taxonomy.legacy_canonical_name, - taxon_group_under_review=taxon_group, - author=author_name, + taxonomy_data = model_to_dict( + taxonomy, + exclude=[ + 'id', + 'iucn_status', + 'vernacular_names', + 'author', + 'tags', + 'biographic_distributions', + 'owner', + 'parent']) + taxonomy_update_proposal, created = ( + TaxonomyUpdateProposal.objects.get_or_create( + original_taxonomy=taxonomy, + taxon_group=taxon_group, + status='pending', + new_data=True, + owner=taxonomy.owner, + parent=taxonomy.parent, + taxon_group_under_review=taxon_group, + author=author_name, + iucn_status=taxonomy.iucn_status, + **taxonomy_data + ) ) + if created: + vernacular_names_instances = list(taxonomy.vernacular_names.all()) + taxonomy_update_proposal.vernacular_names.set(vernacular_names_instances) return Response(response) diff --git a/bims/tasks/harvest_gbif_species.py b/bims/tasks/harvest_gbif_species.py index 0d4120180..d7233f4e1 100644 --- a/bims/tasks/harvest_gbif_species.py +++ b/bims/tasks/harvest_gbif_species.py @@ -8,7 +8,6 @@ def harvest_gbif_species(session_id): from bims.utils.logger import log from bims.models import HarvestSession from bims.utils.gbif import find_species_by_area - from bims.enums import TaxonomicRank try: harvest_session = ( @@ -30,7 +29,7 @@ def harvest_gbif_species(session_id): parent_species = harvest_session.module_group.gbif_parent_species - taxa = find_species_by_area( + find_species_by_area( harvest_session.boundary_id, harvest_session=harvest_session, parent_species=parent_species, diff --git a/bims/templates/harvest_gbif_species.html b/bims/templates/harvest_gbif_species.html index bab849a6f..d63e0ab4d 100644 --- a/bims/templates/harvest_gbif_species.html +++ b/bims/templates/harvest_gbif_species.html @@ -38,6 +38,15 @@

Harvest GBIF species

+ + {% if messages %} + + {% endif %} +