From c96db106a8efd5faae1c40b02e31319638b61ffc Mon Sep 17 00:00:00 2001 From: Dimas Ciputra Date: Fri, 20 Oct 2023 11:02:21 +0700 Subject: [PATCH] Update ecosystem characteristic panel (#3543) --- bims/api_views/location_site.py | 33 +++++++++++++++++-- bims/api_views/location_site_public.py | 2 +- bims/enums/ecosystem_type.py | 1 + bims/models/location_site.py | 2 +- bims/scripts/collection_csv_keys.py | 2 +- bims/serializers/bio_collection_serializer.py | 6 ++-- bims/templates/includes/overview_table.html | 2 +- bims/views/site_visit/list.py | 13 ++++---- .../commands/import_collection_data.py | 2 +- 9 files changed, 45 insertions(+), 18 deletions(-) diff --git a/bims/api_views/location_site.py b/bims/api_views/location_site.py index eba2d44b7..f968286ad 100644 --- a/bims/api_views/location_site.py +++ b/bims/api_views/location_site.py @@ -58,6 +58,7 @@ ) from bims.tasks.email_csv import send_csv_via_email from bims.tasks.collection_record import download_gbif_ids +from bims.enums.ecosystem_type import ECOSYSTEM_WETLAND class LocationSiteList(APIView): @@ -559,9 +560,14 @@ def get_site_details(self, site_id): if preferences.SiteSetting.site_code_generator == 'fbis': river_and_geo = OrderedDict() + river_and_geo['River/Wetland/Open Waterbody/Unspecified'] = ( + location_site.ecosystem_type + ) river_and_geo['River'] = site_river river_and_geo[ - 'User River Name'] = location_site.legacy_river_name + 'User River Name'] = ( + location_site.legacy_river_name if location_site.legacy_river_name else '-' + ) river_and_geo['Geomorphological zone'] = ( location_context.value_from_key( 'geo_class_recoded') @@ -571,10 +577,31 @@ def get_site_details(self, site_id): refined_geomorphological = ( location_site.refined_geomorphological ) - river_and_geo['Original Geomorphological zone'] = ( + river_and_geo['User Geomorphological zone'] = ( refined_geomorphological ) - result['River and Geomorphological Zone'] = river_and_geo + river_and_geo['Wetland Name (NWM6)'] = ( + location_site.wetland_name if location_site.wetland_name else '-' + ) + river_and_geo['User Wetland Name'] = ( + location_site.user_wetland_name if location_site.user_wetland_name else '-' + ) + river_and_geo['Hydrogeomorphic Type (NWM6)'] = ( + location_site.hydrogeomorphic_type if location_site.hydrogeomorphic_type else '-' + ) + river_and_geo['User Hydrogeomorphic Type'] = ( + location_site.user_hydrogeomorphic_type if location_site.user_hydrogeomorphic_type else '-' + ) + + wetland_area = '' + if location_site.ecosystem_type == ECOSYSTEM_WETLAND and location_site.additional_data: + wetland_area = location_site.additional_data.get('area_ha', '') + + river_and_geo['Wetland area (hectares)'] = ( + wetland_area if wetland_area else '-' + ) + + result['Ecosystem Characteristics'] = river_and_geo # Location context group data location_context_filters = ( diff --git a/bims/api_views/location_site_public.py b/bims/api_views/location_site_public.py index 337817668..a559f3cd4 100644 --- a/bims/api_views/location_site_public.py +++ b/bims/api_views/location_site_public.py @@ -270,7 +270,7 @@ def get_site_details(self, site_id): refined_geomorphological = ( location_site.refined_geomorphological ) - river_and_geo['Original Geomorphological zone'] = ( + river_and_geo['User Geomorphological zone'] = ( refined_geomorphological ) result['River and Geomorphological Zone'] = river_and_geo diff --git a/bims/enums/ecosystem_type.py b/bims/enums/ecosystem_type.py index 86c3ccc78..718080f05 100644 --- a/bims/enums/ecosystem_type.py +++ b/bims/enums/ecosystem_type.py @@ -1,6 +1,7 @@ ECOSYSTEM_RIVER = 'River' ECOSYSTEM_WETLAND = 'Wetland' ECOSYSTEM_OPEN_WATERBODY = 'Open waterbody' +ECOSYSTEM_UNSPECIFIED = 'Unspecified' ECOSYSTEM_TYPE_CHOICES = ( (ECOSYSTEM_RIVER, ECOSYSTEM_RIVER), diff --git a/bims/models/location_site.py b/bims/models/location_site.py index e858ad839..ae9557c20 100644 --- a/bims/models/location_site.py +++ b/bims/models/location_site.py @@ -66,7 +66,7 @@ class LocationSite(DocumentLinksMixin, AbstractValidation): blank=True, null=True, max_length=200, - verbose_name='Original geomorphological', + verbose_name='User geomorphological', choices=[(g.value, g.value) for g in GeomorphologicalZoneCategory], help_text='Would be used in preference to the one discovered ' 'in geocontext', diff --git a/bims/scripts/collection_csv_keys.py b/bims/scripts/collection_csv_keys.py index 16475ed2f..425a9e7d2 100644 --- a/bims/scripts/collection_csv_keys.py +++ b/bims/scripts/collection_csv_keys.py @@ -13,7 +13,7 @@ FBIS_SITE_CODE = 'FBIS Site Code' SITE_DESCRIPTION = 'Site description' REFINED_GEO_ZONE = 'Refined Geomorphological Zone' -ORIGINAL_GEO_ZONE = 'Original Geomorphological Zone' +ORIGINAL_GEO_ZONE = 'User Geomorphological Zone' USER_HYDROGEOMORPHIC_TYPE = 'User Hydrogeomorphic Type' ENDEMISM = 'Endemism' CATEGORY = 'Category' diff --git a/bims/serializers/bio_collection_serializer.py b/bims/serializers/bio_collection_serializer.py index 6c379ea73..d8ac77607 100644 --- a/bims/serializers/bio_collection_serializer.py +++ b/bims/serializers/bio_collection_serializer.py @@ -101,7 +101,7 @@ class BioCollectionOneRowSerializer( site_code = serializers.SerializerMethodField() user_site_code = serializers.SerializerMethodField() site_description = serializers.SerializerMethodField() - original_geomorphological_zone = serializers.SerializerMethodField() + user_geomorphological_zone = serializers.SerializerMethodField() river_name = serializers.SerializerMethodField() latitude = serializers.SerializerMethodField() longitude = serializers.SerializerMethodField() @@ -264,7 +264,7 @@ def get_user_river_name(self, obj): return obj.site.legacy_river_name return '-' - def get_original_geomorphological_zone(self, obj): + def get_user_geomorphological_zone(self, obj): if obj.site.refined_geomorphological: return obj.site.refined_geomorphological return '-' @@ -633,7 +633,7 @@ class Meta: 'site_code', 'ecosystem_type', 'site_description', - 'original_geomorphological_zone', + 'user_geomorphological_zone', 'latitude', 'longitude', 'sampling_date', diff --git a/bims/templates/includes/overview_table.html b/bims/templates/includes/overview_table.html index f90a28dfb..6f0728bbd 100644 --- a/bims/templates/includes/overview_table.html +++ b/bims/templates/includes/overview_table.html @@ -53,7 +53,7 @@ let $table = $('.summary-table tbody'); let tableData = { 'Geomorphological zone': '-', - 'Original Geomorphological zone': refinedGeomorphologicalZone, + 'User Geomorphological zone': refinedGeomorphologicalZone, 'Catchments': 'title', 'Primary Catchment': '-', 'Secondary Catchment': '-', diff --git a/bims/views/site_visit/list.py b/bims/views/site_visit/list.py index 80ab4f539..837d6a63b 100644 --- a/bims/views/site_visit/list.py +++ b/bims/views/site_visit/list.py @@ -5,7 +5,12 @@ from django.contrib.auth import get_user_model from django.db.models import Subquery, OuterRef from bims.models.survey import Survey -from bims.models.location_site import LocationSite +from bims.enums.ecosystem_type import ( + ECOSYSTEM_RIVER, + ECOSYSTEM_WETLAND, + ECOSYSTEM_OPEN_WATERBODY, + ECOSYSTEM_UNSPECIFIED +) from bims.models.biological_collection_record import BiologicalCollectionRecord from bims.models.taxon_group import TaxonGroup, TaxonomicGroupCategory from bims.api_views.search import CollectionSearch @@ -41,12 +46,6 @@ def get_queryset(self): # Base queryset qs = super(SiteVisitListView, self).get_queryset() - # Get all ecosystem type - search_filters['ecosystemType'] = ','.join(list( - LocationSite.objects.all().values_list( - 'ecosystem_type', flat=True).distinct() - )) - if search_filters: search = CollectionSearch(search_filters) diff --git a/scripts/management/commands/import_collection_data.py b/scripts/management/commands/import_collection_data.py index a778b88b3..10e9d934b 100644 --- a/scripts/management/commands/import_collection_data.py +++ b/scripts/management/commands/import_collection_data.py @@ -65,7 +65,7 @@ FBIS_SITE_CODE = 'FBIS Site Code' SITE_DESCRIPTION = 'Site description' REFINED_GEO_ZONE = 'Refined Geomorphological Zone' -ORIGINAL_GEO_ZONE = 'Original Geomorphological Zone' +ORIGINAL_GEO_ZONE = 'User Geomorphological Zone' ENDEMISM = 'Endemism' CATEGORY = 'Category' ORIGIN = 'Origin'