def get(self, request, pk, format=None): taxon = self.get_object(pk) serializer = TaxonSerializer(taxon) data = serializer.data records = BiologicalCollectionRecord.objects.filter( taxon_gbif_id=taxon ) # Endemism endemism_value = '' endemism = records.values_list('endemism', flat=True).distinct() if endemism: endemism_value = endemism[0] data['endemism'] = endemism_value # Origins origin_value = '' origin = records.values_list('category', flat=True).distinct() if origin: for category in BiologicalCollectionRecord.CATEGORY_CHOICES: if category[0] == origin[0]: origin_value = category[1] data['origin'] = origin_value data['count'] = records.count() return Response(data)
def get(self, request, pk, format=None): taxon = self.get_object(pk) serializer = TaxonSerializer(taxon) data = serializer.data records = BiologicalCollectionRecord.objects.filter(taxonomy=taxon) # Endemism if taxon.endemism: data['endemism'] = taxon.endemism.name # Origins origin_value = '' origin = records.values_list('category', flat=True).distinct() if origin: for category in BiologicalCollectionRecord.CATEGORY_CHOICES: if category[0] == origin[0]: origin_value = category[1] data['origin'] = origin_value data['count'] = records.count() # Taxonomic rank tree taxonomic_rank = self.get_taxonomic_rank_values(taxon) for rank in taxonomic_rank: data.update(rank) return Response(data)
def get(self, request, *args): taxon_group_id = request.GET.get('taxonGroup', '') rank = request.GET.get('rank', '') taxon_name = request.GET.get('taxon', '') if not taxon_group_id: raise Http404('Missing taxon group id') try: taxon_group = TaxonGroup.objects.get(id=taxon_group_id) except TaxonGroup.DoesNotExist: raise Http404('Taxon group does not exist') taxon_list = taxon_group.taxonomies.all() if rank: taxon_list = taxon_list.filter(rank=rank) if taxon_name: taxon_list = taxon_list.filter( canonical_name__icontains=taxon_name) page = self.paginate_queryset(taxon_list) if page is not None: serializer = self.get_paginated_response( TaxonSerializer(page, many=True).data) else: serializer = TaxonSerializer(taxon_list, many=True) return Response(serializer.data)
def get(self, request, pk, format=None): taxon = self.get_object(pk) serializer = TaxonSerializer(taxon) data = serializer.data records = BiologicalCollectionRecord.objects.filter(validated=True, taxonomy=taxon) # Endemism if taxon.endemism: data['endemism'] = taxon.endemism.name # Origins origin_value = '' origin = records.values_list('category', flat=True).distinct() if origin: for category in BiologicalCollectionRecord.CATEGORY_CHOICES: if category[0] == origin[0]: origin_value = category[1] data['origin'] = origin_value data['count'] = records.count() data['total_sites'] = records.distinct('site').count() # Taxonomic rank tree taxonomic_rank = self.get_taxonomic_rank_values(taxon) for rank in taxonomic_rank: data.update(rank) common_names = [] # Common name if taxon.vernacular_names.filter(language='eng').exists(): common_names = list( taxon.vernacular_names.all().filter(language='eng').values()) elif taxon.vernacular_names.all().values().exists(): common_names = list(taxon.vernacular_names.all().values()) if len(common_names) == 0: data['common_name'] = 'Unknown' else: data['common_name'] = str(common_names[0]['name']).capitalize() return Response(data)
def get(self, request, pk, format=None): taxon = self.get_object(pk) serializer = TaxonSerializer(taxon) return Response(serializer.data)
def get_taxonomy(self, obj): return TaxonSerializer(obj.taxonomy).data