From c9e48d1b33d0f5c5652f6545a644c241075b4ab5 Mon Sep 17 00:00:00 2001 From: Hakan Date: Fri, 15 Nov 2024 16:25:41 +0300 Subject: [PATCH 1/5] limit export access log to the last access --- CHANGES | 15 ++++++++++----- src/etools_datamart/__init__.py | 2 +- src/unicef_rest_framework/models/export.py | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/CHANGES b/CHANGES index 868f3313..639f479b 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,11 @@ +4.7.13 +---- +* ExportAccessLog usage has been simplified by keeping the last access as the sole purpose + it to see if an export is in use at all. + 4.7.12 ---- -Formula for SpotCheckFindings.pending_unsupported_amount has been updated as below; +* Formula for SpotCheckFindings.pending_unsupported_amount has been updated as below; = audit_spotcheck.total_amount_of_ineligible_expenditure audit_engagement.additional_supporting_documentation_provided audit_engagement.justification_provided_and_accepted @@ -9,19 +14,19 @@ Formula for SpotCheckFindings.pending_unsupported_amount has been updated as bel 4.7.11 ---- -CI pipline improvements for version tagging. +* CI pipline improvements for version tagging. 4.7.10 ---- -Further improve Celery task failure error report +* Further improve Celery task failure error report 4.7.9 ---- -Make groups parameter name consistent +* Make groups parameter name consistent ---- -Hotfix for export access log to handle non-standard date format +* Hotfix for export access log to handle non-standard date format 4.7.6 ---- diff --git a/src/etools_datamart/__init__.py b/src/etools_datamart/__init__.py index 8a2d0aee..5a1a57cd 100644 --- a/src/etools_datamart/__init__.py +++ b/src/etools_datamart/__init__.py @@ -1,3 +1,3 @@ NAME = "etools-datamart" -VERSION = __version__ = "4.7.12" +VERSION = __version__ = "4.7.13" __author__ = "" diff --git a/src/unicef_rest_framework/models/export.py b/src/unicef_rest_framework/models/export.py index 991aa466..59beff90 100644 --- a/src/unicef_rest_framework/models/export.py +++ b/src/unicef_rest_framework/models/export.py @@ -149,7 +149,7 @@ def log_access(cls, export, username): try: access_log = cls.objects.get(export=export) - access_log.access_history.append(log_entry) + access_log.access_history = [log_entry] access_log.save() except cls.DoesNotExist: cls.objects.create(export=export, access_history=[log_entry]) From 06fb7a9a61a158d65d5c76a81d8d7eec4d7a7eb2 Mon Sep 17 00:00:00 2001 From: Hakan Date: Wed, 18 Dec 2024 16:48:17 +0300 Subject: [PATCH 2/5] extract latitide and longitude from point and geom fields if they happen to be null --- CHANGES | 5 ++++ src/etools_datamart/__init__.py | 2 +- .../apps/mart/data/models/fm_questions.py | 30 ++++++++++++++++--- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/CHANGES b/CHANGES index 868f3313..41b91196 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,8 @@ +4.7.13 +---- +* Improved FMQuestion and FMOntrack loaders to extract latitude and longitude from +Location.point when Location.longitude and Location.latitude. + 4.7.12 ---- Formula for SpotCheckFindings.pending_unsupported_amount has been updated as below; diff --git a/src/etools_datamart/__init__.py b/src/etools_datamart/__init__.py index 8a2d0aee..5a1a57cd 100644 --- a/src/etools_datamart/__init__.py +++ b/src/etools_datamart/__init__.py @@ -1,3 +1,3 @@ NAME = "etools-datamart" -VERSION = __version__ = "4.7.12" +VERSION = __version__ = "4.7.13" __author__ = "" diff --git a/src/etools_datamart/apps/mart/data/models/fm_questions.py b/src/etools_datamart/apps/mart/data/models/fm_questions.py index 8c5298b1..840e4213 100644 --- a/src/etools_datamart/apps/mart/data/models/fm_questions.py +++ b/src/etools_datamart/apps/mart/data/models/fm_questions.py @@ -25,6 +25,28 @@ logger = get_task_logger(__name__) +def extract_latitude(location): + if location.latitude is not None: + return location.latitude + elif location.point is not None: + return location.point.y + elif location.geom is not None: + return location.centroid.y + else: + return None + + +def extract_longitude(location): + if location.longitude is not None: + return location.latitude + elif location.point is not None: + return location.point.x + elif location.geom is not None: + return location.centroid.x + else: + return None + + class FMQuestionLoader(EtoolsLoader): """Loader for FM Questions""" @@ -244,8 +266,8 @@ def get_location(self, record: FieldMonitoringDataCollectionFinding, values: dic "admin_level": instance.admin_level, "source_id": instance.source_id, "location_type": instance.admin_level_name, - "latitude": instance.latitude, - "longitude": instance.longitude, + "latitude": extract_latitude(instance), + "longitude": extract_longitude(instance), } except Location.DoesNotExist: return {key: "N/A" for key in loc_fields} @@ -486,8 +508,8 @@ def get_location(self, record: FieldMonitoringDataCollectionActivityoverallfindi "admin_level": instance.admin_level, "source_id": instance.source_id, "location_type": instance.admin_level_name, - "latitude": instance.latitude, - "longitude": instance.longitude, + "latitude": extract_latitude(instance), + "longitude": extract_longitude(instance), } except Location.DoesNotExist: return {key: "N/A" for key in loc_fields} From a37ae8a8844878953cf23033132e002f34ba0972 Mon Sep 17 00:00:00 2001 From: Hakan Date: Thu, 19 Dec 2024 17:32:30 +0300 Subject: [PATCH 3/5] fix logical error regarding longitude function --- CHANGES | 4 ++++ src/etools_datamart/__init__.py | 2 +- src/etools_datamart/apps/mart/data/models/fm_questions.py | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 41b91196..8ba0bbfa 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +4.7.14 +---- +* Fix logic error extract_longitude function + 4.7.13 ---- * Improved FMQuestion and FMOntrack loaders to extract latitude and longitude from diff --git a/src/etools_datamart/__init__.py b/src/etools_datamart/__init__.py index 5a1a57cd..2a7dd1b1 100644 --- a/src/etools_datamart/__init__.py +++ b/src/etools_datamart/__init__.py @@ -1,3 +1,3 @@ NAME = "etools-datamart" -VERSION = __version__ = "4.7.13" +VERSION = __version__ = "4.7.14" __author__ = "" diff --git a/src/etools_datamart/apps/mart/data/models/fm_questions.py b/src/etools_datamart/apps/mart/data/models/fm_questions.py index 840e4213..6213bf0f 100644 --- a/src/etools_datamart/apps/mart/data/models/fm_questions.py +++ b/src/etools_datamart/apps/mart/data/models/fm_questions.py @@ -38,7 +38,7 @@ def extract_latitude(location): def extract_longitude(location): if location.longitude is not None: - return location.latitude + return location.longitude elif location.point is not None: return location.point.x elif location.geom is not None: From dcef1f6d5f12cfcafea6f93350d7959ada3ae273 Mon Sep 17 00:00:00 2001 From: Hakan Date: Fri, 15 Nov 2024 16:25:41 +0300 Subject: [PATCH 4/5] limit export access log to the last access --- CHANGES | 16 +++++++++++----- src/etools_datamart/__init__.py | 2 +- src/unicef_rest_framework/models/export.py | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/CHANGES b/CHANGES index 8ba0bbfa..f1347a52 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,9 @@ + +4.7.15 +---- +* ExportAccessLog usage has been simplified by keeping the last access as the sole purpose + it to see if an export is in use at all. + 4.7.14 ---- * Fix logic error extract_longitude function @@ -9,7 +15,7 @@ Location.point when Location.longitude and Location.latitude. 4.7.12 ---- -Formula for SpotCheckFindings.pending_unsupported_amount has been updated as below; +* Formula for SpotCheckFindings.pending_unsupported_amount has been updated as below; = audit_spotcheck.total_amount_of_ineligible_expenditure audit_engagement.additional_supporting_documentation_provided audit_engagement.justification_provided_and_accepted @@ -18,19 +24,19 @@ Formula for SpotCheckFindings.pending_unsupported_amount has been updated as bel 4.7.11 ---- -CI pipline improvements for version tagging. +* CI pipline improvements for version tagging. 4.7.10 ---- -Further improve Celery task failure error report +* Further improve Celery task failure error report 4.7.9 ---- -Make groups parameter name consistent +* Make groups parameter name consistent ---- -Hotfix for export access log to handle non-standard date format +* Hotfix for export access log to handle non-standard date format 4.7.6 ---- diff --git a/src/etools_datamart/__init__.py b/src/etools_datamart/__init__.py index 2a7dd1b1..f7c6faf2 100644 --- a/src/etools_datamart/__init__.py +++ b/src/etools_datamart/__init__.py @@ -1,3 +1,3 @@ NAME = "etools-datamart" -VERSION = __version__ = "4.7.14" +VERSION = __version__ = "4.7.15" __author__ = "" diff --git a/src/unicef_rest_framework/models/export.py b/src/unicef_rest_framework/models/export.py index 991aa466..59beff90 100644 --- a/src/unicef_rest_framework/models/export.py +++ b/src/unicef_rest_framework/models/export.py @@ -149,7 +149,7 @@ def log_access(cls, export, username): try: access_log = cls.objects.get(export=export) - access_log.access_history.append(log_entry) + access_log.access_history = [log_entry] access_log.save() except cls.DoesNotExist: cls.objects.create(export=export, access_history=[log_entry]) From 254418b6767ad296f5b041e8161bf1a680c6097d Mon Sep 17 00:00:00 2001 From: Hakan Date: Tue, 24 Dec 2024 15:01:39 +0300 Subject: [PATCH 5/5] leave not more than 3 access logs --- src/unicef_rest_framework/models/export.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/unicef_rest_framework/models/export.py b/src/unicef_rest_framework/models/export.py index 59beff90..c2e1acb3 100644 --- a/src/unicef_rest_framework/models/export.py +++ b/src/unicef_rest_framework/models/export.py @@ -149,7 +149,11 @@ def log_access(cls, export, username): try: access_log = cls.objects.get(export=export) - access_log.access_history = [log_entry] + + while len(access_log.access_history) >= 3: + access_log.access_history.pop(0) + + access_log.access_history.append(log_entry) access_log.save() except cls.DoesNotExist: cls.objects.create(export=export, access_history=[log_entry])