Пример #1
0
    def post(self, request, *args):
        response = {
            'id': '',
            'taxon_name': '',
        }
        taxonomy = None
        gbif_key = self.request.POST.get('gbifKey', None)
        taxon_name = self.request.POST.get('taxonName', None)
        taxon_group = self.request.POST.get('taxonGroup', None)
        rank = self.request.POST.get('rank', None)
        if gbif_key:
            taxonomy = process_taxon_identifier(key=gbif_key,
                                                fetch_parent=True,
                                                get_vernacular=False)
        elif taxon_name and rank:
            taxonomy, created = Taxonomy.objects.get_or_create(
                scientific_name=taxon_name,
                canonical_name=taxon_name,
                rank=rank)
            if taxon_group:
                try:
                    taxon_group = TaxonGroup.objects.get(name=taxon_group)
                    taxon_group.taxonomies.add(taxonomy)
                except TaxonGroup.DoesNotExist:
                    pass
        if taxonomy:
            response['id'] = taxonomy.id
            response['taxon_name'] = taxonomy.canonical_name

        return Response(response)
 def test_get_all_parent(self):
     taxon_identifier = process_taxon_identifier(self.gbif_key)
     parent = 0
     while taxon_identifier.parent:
         self.assertIsNotNone(taxon_identifier.parent)
         parent += 1
         taxon_identifier = taxon_identifier.parent
     self.assertTrue(parent == 2)
Пример #3
0
    def handle(self, *args, **options):
        models.signals.pre_save.disconnect(
            taxonomy_pre_save_handler,
        )
        models.signals.post_save.disconnect(
            collection_post_save_handler,
        )

        taxonomy_gbif_keys = Taxonomy.objects.values_list(
            'gbif_key',
            flat=True
        )
        taxa = Taxon.objects.all().exclude(
            gbif_id__in=taxonomy_gbif_keys
        )
        for taxon in taxa:
            print('Migrate %s' % taxon.scientific_name)
            taxon_identifier = process_taxon_identifier(taxon.gbif_id)
            if taxon_identifier:
                taxon_identifier.iucn_data = taxon.iucn_data
                taxon_identifier.iucn_redlist_id = taxon.iucn_redlist_id
                taxon_identifier.author = taxon.author
                taxon_identifier.endemism = taxon.endemism
                taxon_identifier.save()
                if taxon.iucn_status:
                    iucn_status = IUCNStatus.objects.get(
                        pk=taxon.iucn_status.pk)
                    taxonomy = Taxonomy.objects.get(id=taxon_identifier.id)
                    taxonomy.iucn_status = iucn_status
                    taxonomy.save()

        collections = BiologicalCollectionRecord.objects.filter(
            taxonomy__isnull=True,
        )
        for collection in collections:
            update_collection_record(collection)

        models.signals.post_save.connect(
            collection_post_save_handler,
        )
 def test_get_children(self):
     taxon_identifier = process_taxon_identifier(self.gbif_key)
     parent = taxon_identifier.parent
     self.assertTrue(len(parent.get_direct_children()) > 0)
 def test_process_taxon(self):
     taxon_identifier = process_taxon_identifier(self.gbif_key, False)
     scientific_name = 'Elasmobranchii'
     self.assertEqual(scientific_name, taxon_identifier.scientific_name)