Skip to content

Commit 7e7d794

Browse files
authored
Handle embargo_date in occurrence uploader (#5094)
1 parent b4fb7c2 commit 7e7d794

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

bims/download/collection_record.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import shutil
88

99
from bims.models.download_request import DownloadRequest
10-
from bims.scripts.collection_csv_keys import PARK_OR_MPA_NAME
10+
from bims.scripts.collection_csv_keys import PARK_OR_MPA_NAME, END_EMBARGO_DATE
1111

1212
logger = logging.getLogger(__name__)
1313

@@ -37,7 +37,8 @@ def queryset_iterator(qs, batch_size=500, gc_collect=True):
3737
'sub_species': 'SubSpecies',
3838
'cites_listing': 'CITES listing',
3939
'park_or_mpa_name': PARK_OR_MPA_NAME,
40-
'authors': 'Author(s)'
40+
'authors': 'Author(s)',
41+
'end_embargo_date': END_EMBARGO_DATE,
4142
}
4243

4344

bims/scripts/collection_csv_keys.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,4 @@
100100
CERTAINTY_OF_IDENTIFICATION = 'Certainty'
101101
DATE_ACCURACY = 'Date Accuracy'
102102
DATA_TYPE = 'Data type'
103+
END_EMBARGO_DATE = 'End Embargo Date'

bims/scripts/occurrences_upload.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from bims.scripts.collection_csv_keys import * # noqa
99
from datetime import datetime
10+
from dateutil.parser import parse as parse_datetime
1011

1112
from django.contrib.gis.geos import Point
1213
from django.db.models import Q
@@ -642,6 +643,20 @@ def process_data(self, row):
642643
if not sampling_date:
643644
return
644645

646+
# -- End embargo date
647+
end_embargo_date = None
648+
end_embargo_date_str = DataCSVUpload.row_value(row, END_EMBARGO_DATE)
649+
if end_embargo_date_str:
650+
try:
651+
end_embargo_date = parse_datetime(
652+
timestr=end_embargo_date_str, dayfirst=True)
653+
except Exception:
654+
self.handle_error(
655+
row=row,
656+
message=f"Incorrect end embargo date format: {end_embargo_date_str}"
657+
)
658+
return
659+
645660
# -- Processing Taxonomy
646661
taxonomy = self.taxonomy(row)
647662
if not taxonomy:
@@ -685,6 +700,12 @@ def process_data(self, row):
685700
collector=collectors[0],
686701
)
687702

703+
# -- Apply end embargo date to the survey
704+
if end_embargo_date and self.survey:
705+
Survey.objects.filter(id=self.survey.id).update(
706+
end_embargo_date=end_embargo_date
707+
)
708+
688709
# -- Optional data - Present
689710
if PRESENT in row:
690711
optional_data["present"] = bool(DataCSVUpload.row_value(row, PRESENT))
@@ -794,6 +815,10 @@ def process_data(self, row):
794815
wetland_indicator_status = None
795816
optional_data["wetland_indicator_status"] = wetland_indicator_status
796817

818+
# -- End embargo date on the occurrence record
819+
if end_embargo_date:
820+
optional_data["end_embargo_date"] = end_embargo_date
821+
797822
# -- Processing chemical records
798823
self.chemical_records(row, location_site, sampling_date)
799824

bims/serializers/bio_collection_serializer.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ class BioCollectionOneRowSerializer(
161161
cites_listing = serializers.SerializerMethodField()
162162
data_type = serializers.SerializerMethodField()
163163
dataset = serializers.SerializerMethodField()
164+
end_embargo_date = serializers.SerializerMethodField()
164165

165166
@staticmethod
166167
def _has_value(v) -> bool:
@@ -703,6 +704,11 @@ def get_data_type(self, obj: BiologicalCollectionRecord):
703704
return obj.data_type.capitalize()
704705
return 'Public'
705706

707+
def get_end_embargo_date(self, obj: BiologicalCollectionRecord):
708+
if obj.end_embargo_date:
709+
return obj.end_embargo_date.isoformat()
710+
return ''
711+
706712
class Meta:
707713
model = BiologicalCollectionRecord
708714
fields = [
@@ -769,7 +775,8 @@ class Meta:
769775
'dataset',
770776
'dataset_key',
771777
'cites_listing',
772-
'data_type'
778+
'data_type',
779+
'end_embargo_date',
773780
]
774781

775782
def _get_geocontext_parks_group(self):

0 commit comments

Comments
 (0)