Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ecosystem type #3447

Merged
merged 5 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bims/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,8 @@ class Media:
'taxonomy',
'taxonomy__origin',
'record_type',
'sampling_method'
'sampling_method',
'ecosystem_type'
)
search_fields = (
'taxonomy__scientific_name',
Expand Down
14 changes: 14 additions & 0 deletions bims/api_views/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,14 @@ def modules(self):
else:
return None

@property
def ecosystem_type(self):
ecosystem_type = self.get_request_data('ecosystemType')
if ecosystem_type:
return ecosystem_type.split(',')
else:
return None

@property
def spatial_filter(self):
spatial_filters = self.parse_request_json('spatialFilter')
Expand Down Expand Up @@ -661,6 +669,12 @@ def process_search(self):
))
bio_filtered = True

if self.ecosystem_type:
bio = bio.filter(
ecosystem_type__in=self.ecosystem_type
)
bio_filtered = True

if self.modules:
# For Intersection methods :
if len(self.modules) > 1:
Expand Down
9 changes: 9 additions & 0 deletions bims/enums/ecosystem_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ECOSYSTEM_RIVER = 'River'
ECOSYSTEM_WETLAND = 'Wetland'
ECOSYSTEM_OPEN_WATERBODY = 'Open waterbody'

ECOSYSTEM_TYPE_CHOICES = (
(ECOSYSTEM_RIVER, ECOSYSTEM_RIVER),
(ECOSYSTEM_WETLAND, ECOSYSTEM_WETLAND),
(ECOSYSTEM_OPEN_WATERBODY, ECOSYSTEM_OPEN_WATERBODY)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.1.10 on 2023-08-22 02:30

from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('bims', '0341_remove_bimsdocument_profile_locationsite_wetland_id_and_more'),
]

operations = [
migrations.AddField(
model_name='biologicalcollectionrecord',
name='ecosystem_type',
field=models.CharField(blank=True, choices=[('River', 'River'), ('Wetland', 'Wetland'), ('Open waterbody', 'Open waterbody')], default='', max_length=128, null=True),
), ]
20 changes: 20 additions & 0 deletions bims/migrations/0343_locationsite_ecosystem_type_and_more.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 4.1.10 on 2023-08-23 01:01

from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('bims', '0342_biologicalcollectionrecord_ecosystem_type_and_more'),
]

operations = [
migrations.AddField(
model_name='locationsite',
name='ecosystem_type',
field=models.CharField(blank=True, choices=[('River', 'River'), ('Wetland', 'Wetland'), ('Open waterbody', 'Open waterbody')], default='', max_length=128, null=True),
),
]
9 changes: 9 additions & 0 deletions bims/models/biological_collection_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from bims.enums.taxonomic_group_category import TaxonomicGroupCategory
from bims.models.bims_document import BimsDocument
from bims.models.survey import Survey
from bims.enums.ecosystem_type import ECOSYSTEM_TYPE_CHOICES
from td_biblio.models import Entry


Expand Down Expand Up @@ -321,6 +322,14 @@ class BiologicalCollectionRecord(AbstractValidation):
null=True
)

ecosystem_type = models.CharField(
max_length=128,
blank=True,
choices=ECOSYSTEM_TYPE_CHOICES,
default='',
null=True
)

@property
def data_name(self):
return self.original_species_name
Expand Down
10 changes: 9 additions & 1 deletion bims/models/location_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
from bims.models.location_type import LocationType
from bims.utils.get_key import get_key
from bims.models.document_links_mixin import DocumentLinksMixin
from bims.models.search_process import SearchProcess
from bims.enums.geomorphological_zone import GeomorphologicalZoneCategory
from bims.models.location_context import LocationContext
from bims.models.location_context_group import LocationContextGroup
from bims.utils.decorator import prevent_recursion
from bims.enums.ecosystem_type import ECOSYSTEM_TYPE_CHOICES

LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -173,6 +173,14 @@ class LocationSite(DocumentLinksMixin, AbstractValidation):
max_length=256
)

ecosystem_type = models.CharField(
max_length=128,
blank=True,
choices=ECOSYSTEM_TYPE_CHOICES,
default='',
null=True
)

@property
def location_site_identifier(self):
"""
Expand Down
1 change: 1 addition & 0 deletions bims/scripts/collection_csv_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
BROAD_BIOTOPE = 'Broad biotope'
SPECIFIC_BIOTOPE = 'Specific biotope'
SUBSTRATUM = 'Substratum'
ECOSYSTEM_TYPE = 'Ecosystem type'

# Chemical records
TEMP = 'TEMP'
Expand Down
19 changes: 16 additions & 3 deletions bims/scripts/occurrences_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,11 @@ def process_survey(self, record, location_site, sampling_date, collector):
def location_site(self, record):
""" Process location site data """
location_site = None

# -- Ecosystem type
ecosystem_type = DataCSVUpload.row_value(
record, ECOSYSTEM_TYPE)

location_type, status = LocationType.objects.get_or_create(
name='PointObservation',
allowed_geometry='POINT'
Expand Down Expand Up @@ -292,21 +297,24 @@ def location_site(self, record):
if len(str(latitude)) > 5 and len(str(longitude)) > 5:
location_site = LocationSite.objects.filter(
latitude__startswith=latitude,
longitude__startswith=longitude
longitude__startswith=longitude,
ecosystem_type=ecosystem_type
).first()

if not location_site:
try:
location_site, status = (
LocationSite.objects.get_or_create(
location_type=location_type,
geometry_point=record_point
geometry_point=record_point,
ecosystem_type=ecosystem_type
)
)
except LocationSite.MultipleObjectsReturned:
location_site = LocationSite.objects.filter(
location_type=location_type,
geometry_point=record_point
geometry_point=record_point,
ecosystem_type=ecosystem_type
).first()
if not location_site.name and location_site_name:
location_site.name = location_site_name
Expand Down Expand Up @@ -700,9 +708,14 @@ def process_data(self, row):
if self.module_group:
record.module_group = self.module_group

# -- Ecosystem type
record.ecosystem_type = DataCSVUpload.row_value(
row, ECOSYSTEM_TYPE)

# -- Additional data
record.additional_data = json.dumps(row)
record.validated = True

record.save()

if not str(record.site.id) in self.site_ids:
Expand Down
1 change: 1 addition & 0 deletions bims/serializers/bio_collection_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,7 @@ class Meta:
'river_name',
'user_site_code',
'site_code',
'ecosystem_type',
'site_description',
'refined_geomorphological_zone',
'latitude',
Expand Down
39 changes: 13 additions & 26 deletions bims/static/js/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,19 @@ define(['backbone', 'views/olmap', 'utils/events_connector', 'shared'], function
"site/:params": "showSingleSiteDetail"
},
initializeParameters: function () {
this.parameters['taxon'] = '';
this.parameters['months'] = '';
this.parameters['siteId'] = '';
this.parameters['search'] = '';
this.parameters['collector'] = '';
this.parameters['category'] = '';
this.parameters['yearFrom'] = '';
this.parameters['yearTo'] = '';
this.parameters['userBoundary'] = '';
this.parameters['referenceCategory'] = '';
this.parameters['boundary'] = '';
this.parameters['reference'] = '';
this.parameters['endemic'] = '';
this.parameters['conservationStatus'] = '';
this.parameters['spatialFilter'] = '';
this.parameters['taxon'] = '';
this.parameters['validated'] = '';
this.parameters['modules'] = '';
this.parameters['sourceCollection'] = '';
this.parameters['ecologicalCategory'] = '';
this.parameters['module'] = '';
this.parameters['rank'] = '';
this.parameters['orderBy'] = '';
this.parameters['siteIdOpen'] = '';
this.parameters['polygon'] = '';
this.parameters['dst'] = '';
const parameterKeys = [
'taxon', 'months', 'siteId', 'search', 'collector',
'category', 'yearFrom', 'yearTo', 'userBoundary', 'referenceCategory',
'boundary', 'reference', 'endemic', 'conservationStatus', 'spatialFilter',
'taxon', 'validated', 'modules', 'sourceCollection', 'ecologicalCategory',
'module', 'rank', 'orderBy', 'siteIdOpen', 'polygon',
'dst', 'ecosystemType'
];

parameterKeys.forEach(key => {
this.parameters[key] = '';
});

if (typeof filterParameters !== 'undefined') {
filterParameters = $.extend(true, {}, this.parameters);
}
Expand Down
2 changes: 1 addition & 1 deletion bims/static/js/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ define(['backbone', 'underscore', 'utils/storage', 'utils/color', 'utils/url', '
"&reference=<%= reference %>&endemic=<%= endemic %>&conservationStatus=<%= conservationStatus %>" +
"&modules=<%= modules %>&validated=<%= validated %>&sourceCollection=<%= sourceCollection %>" +
"&module=<%= module %>&ecologicalCategory=<%= ecologicalCategory %>&rank=<%= rank %>"+
"&siteIdOpen=<%= siteIdOpen %>&orderBy=<%= orderBy %>&polygon=<%= polygon %>&dst=<%= dst %>",
"&siteIdOpen=<%= siteIdOpen %>&orderBy=<%= orderBy %>&polygon=<%= polygon %>&dst=<%= dst %>&ecosystemType=<%= ecosystemType %>",
LocationSiteDetailXHRRequest: null,
MultiSitesOverviewXHRRequest: null,
TaxonDetailXHRRequest: null,
Expand Down
4 changes: 4 additions & 0 deletions bims/static/js/utils/filter_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ let filterParametersJSON = {
'label': 'Site Id',
'type': 'comma'
},
'ecosystemType': {
'label': 'Ecosystem Type',
'type': 'comma'
},
'collector': {
'label': 'Collector',
'type': 'json'
Expand Down
3 changes: 1 addition & 2 deletions bims/static/js/views/detail_dashboard/site_detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -1446,8 +1446,7 @@ define([
continue;
}
}

if(keys[i] === 'DOI/URL' && document && source[keys[i]].indexOf('/uploaded/') > -1) {
if(keys[i] === 'DOI/URL' && document && source[keys[i]] && source[keys[i]].indexOf('/uploaded/') > -1) {
itemDiv.append('<td><a href="'+ source[keys[i]] + '" target="_blank">Download</a></td>')
} else if (keys[i] === 'DOI/URL' && source[keys[i]] && source[keys[i]].substring(0, 4) !== 'http') {
itemDiv.append(`<td><a href="http://dx.doi.org/${source[keys[i]]}" target="_blank">${source[keys[i]]}</a></td>`);
Expand Down
60 changes: 39 additions & 21 deletions bims/static/js/views/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ define([
}
}
let occurrencesFilter = [
'ecosystem-type-container',
'biodiversity-module-container',
'data-source-container',
'validation-status-container',
Expand Down Expand Up @@ -515,6 +516,20 @@ define([
}
filterParameters['validated'] = validated;

// Ecosystem type filter
let ecosystemTypeFilter = [];
let ecosystemType = '';
$('[name=filter-ecosystem-type]:checked').each(function () {
ecosystemTypeFilter.push($(this).attr('value'));
});
if (ecosystemTypeFilter.length > 0 && $('[name=filter-ecosystem-type]').length !== ecosystemTypeFilter.length) {
ecosystemType = ecosystemTypeFilter.join();
self.highlightPanel('.ecosystem-type-row', true);
} else {
self.highlightPanel('.ecosystem-type-row', false);
}
filterParameters['ecosystemType'] = ecosystemType;

// ecological category
var ecologicalConditions = '';
if (self.selectedEcologicalConditions.length > 0) {
Expand Down Expand Up @@ -556,29 +571,18 @@ define([
Shared.Dispatcher.trigger('map:closeHighlight');
Shared.Dispatcher.trigger(Shared.EVENTS.SEARCH.HIT, filterParameters);
Shared.Dispatcher.trigger('sidePanel:closeSidePanel');
if (!filterParameters['search']
&& !filterParameters['collector']
&& !filterParameters['validated']
&& !filterParameters['category']
&& !filterParameters['yearFrom']
&& !filterParameters['yearTo']
&& !filterParameters['userBoundary']
&& !filterParameters['referenceCategory']
&& !filterParameters['reference']
&& !filterParameters['endemic']
&& !filterParameters['modules']
&& !filterParameters['conservationStatus']
&& !filterParameters['spatialFilter']
&& !filterParameters['ecologicalCategory']
&& !filterParameters['sourceCollection']
&& !filterParameters['abioticData']
&& !filterParameters['polygon']
&& !filterParameters['boundary']
&& !filterParameters['dst']
&& !filterParameters['thermalModule']) {
const keysToCheck = [
'search', 'collector', 'validated', 'ecosystemType', 'category',
'yearFrom', 'yearTo', 'userBoundary', 'referenceCategory', 'reference',
'endemic', 'modules', 'conservationStatus', 'spatialFilter',
'ecologicalCategory', 'sourceCollection', 'abioticData', 'polygon',
'boundary', 'dst', 'thermalModule'
];
const hasAnyTruthyValue = keysToCheck.some(key => filterParameters[key]);
if (!hasAnyTruthyValue) {
Shared.Dispatcher.trigger('cluster:updateAdministrative', '');
Shared.Router.clearSearch();
return false
return false;
}
this.searchResultCollection.search(
this.searchPanel,
Expand Down Expand Up @@ -651,6 +655,8 @@ define([
this.searchPanel.clearSidePanel();
this.clearClickedOriginButton();

$('[name=filter-ecosystem-type]').prop('checked', true);

Shared.Dispatcher.trigger('politicalRegion:clear');

Shared.Dispatcher.trigger('spatialFilter:clearSelected');
Expand Down Expand Up @@ -855,6 +861,18 @@ define([
$('[name="module"]').trigger('change');
}

// Search module
if (allFilters.hasOwnProperty('ecosystemType')) {
let ecosystemTypes = allFilters['ecosystemType'].split(',');
$('[name=filter-ecosystem-type]').each(function () {
if (ecosystemTypes.includes($(this).attr('value'))) {
$(this).prop('checked', true);
} else {
$(this).prop('checked', false);
}
});
}

// Collectors
self.initialSelectedCollectors = [];
if (allFilters.hasOwnProperty('collector')) {
Expand Down
Loading
Loading