From 16d67332264ebf87bcdc3ea0281d5b990c7d0cc7 Mon Sep 17 00:00:00 2001 From: Steven Gerrits Date: Mon, 16 Dec 2024 22:18:36 +0100 Subject: [PATCH] dec release 1 --- src/components/FilterComponent.vue | 38 ++++++++++++++----- .../ObservationDetailsComponent.vue | 2 +- src/stores/vespaStore.js | 4 ++ vespadb/observations/serializers.py | 20 ++++++---- vespadb/observations/views.py | 13 ++++--- 5 files changed, 55 insertions(+), 22 deletions(-) diff --git a/src/components/FilterComponent.vue b/src/components/FilterComponent.vue index 1903c45..22ccf08 100644 --- a/src/components/FilterComponent.vue +++ b/src/components/FilterComponent.vue @@ -22,15 +22,35 @@
- - -
-
- - -
+ + + +
+ + +
- +

{{ selectedObservation.notes }}

diff --git a/src/stores/vespaStore.js b/src/stores/vespaStore.js index e59b0b8..d132687 100644 --- a/src/stores/vespaStore.js +++ b/src/stores/vespaStore.js @@ -456,6 +456,10 @@ export const useVespaStore = defineStore('vespaStore', { return '#198754'; } else if (status === 'eradicated') { return '#198754'; + } else if (status === 'untreated') { + return '#198754'; + } else if (status === 'unknown') { + return '#198754'; } else if (status === 'unsuccessful') { return '#198754'; } else if (status === 'reserved') { diff --git a/vespadb/observations/serializers.py b/vespadb/observations/serializers.py index 10cf878..5f0cedb 100644 --- a/vespadb/observations/serializers.py +++ b/vespadb/observations/serializers.py @@ -197,11 +197,11 @@ def get_municipality_name(self, obj: Observation) -> str | None: def get_status(self, obj: Observation) -> str: """Determine the status of the observation based on its properties.""" - if obj.eradication_date: + if obj.eradication_result: return "eradicated" - if obj.reserved_datetime: + if obj.reserved_by: return "reserved" - return "default" + return "untreated" def get_reserved_by_first_name(self, obj: Observation) -> str | None: """Retrieve the first name of the user who reserved the observation.""" @@ -335,7 +335,7 @@ def update(self, instance: Observation, validated_data: dict[Any, Any]) -> Obser # Eradication result logic eradication_result = validated_data.get("eradication_result") - # Check if any eradication-related fields are present without eradication_result + # Define eradication-related fields eradication_related_fields = [ "eradication_date", "eradicator_name", @@ -345,9 +345,17 @@ def update(self, instance: Observation, validated_data: dict[Any, Any]) -> Obser "eradication_aftercare", "eradication_problems", "eradication_notes", + "eradication_product", ] - if any(field in validated_data for field in eradication_related_fields) and eradication_result is None: + # Only check for eradication fields that have non-null values + has_eradication_fields = any( + field in validated_data + and validated_data[field] is not None + for field in eradication_related_fields + ) + + if has_eradication_fields and eradication_result is None: raise serializers.ValidationError( "Eradication result is required when providing eradication-related fields." ) @@ -360,7 +368,6 @@ def update(self, instance: Observation, validated_data: dict[Any, Any]) -> Obser if eradication_result == EradicationResultEnum.SUCCESSFUL: validated_data["reserved_datetime"] = None validated_data["reserved_by"] = None - #validated_data["eradication_date"] = datetime.now(timezone("EST")).date() if not user.is_superuser: # Non-admins cannot update admin-specific fields, so remove them @@ -398,7 +405,6 @@ def update(self, instance: Observation, validated_data: dict[Any, Any]) -> Obser validated_data.pop(field) instance = super().update(instance, validated_data) return instance - def to_internal_value(self, data: dict[str, Any]) -> dict[str, Any]: """Convert the incoming data to a Python native representation.""" logger.info("Raw input data: %s", data) diff --git a/vespadb/observations/views.py b/vespadb/observations/views.py index 7577e03..41b95d6 100644 --- a/vespadb/observations/views.py +++ b/vespadb/observations/views.py @@ -710,8 +710,6 @@ def parse_location(self, srid_str: str) -> tuple[float, float]: def serialize_observation(self, obj: Observation, headers: list[str], allowed_fields: list[str]) -> list[str]: """Serialize an observation for CSV export with specified fields.""" data = [] - logger.info('Serializing observation %s', obj) - logger.info("allowed_fields: %s", allowed_fields) for field in headers: if field not in allowed_fields: data.append("") # Add empty string for restricted fields @@ -732,9 +730,15 @@ def serialize_observation(self, obj: Observation, headers: list[str], allowed_fi elif field in ["created_datetime", "modified_datetime", "observation_datetime"]: datetime_val = getattr(obj, field, None) if datetime_val: - # Remove milliseconds and ensure ISO format with 'T' and 'Z' + # Remove milliseconds and ensure ISO format with 'Z' datetime_val = datetime_val.replace(microsecond=0) - data.append(datetime_val.isoformat() + "Z") + # Convert to ISO format and replace +00:00 with Z if present + iso_datetime = datetime_val.isoformat() + if iso_datetime.endswith('+00:00'): + iso_datetime = iso_datetime[:-6] + 'Z' + elif not iso_datetime.endswith('Z'): + iso_datetime += 'Z' + data.append(iso_datetime) else: data.append("") elif field == "province": @@ -747,7 +751,6 @@ def serialize_observation(self, obj: Observation, headers: list[str], allowed_fi data.append(obj.eradication_result if obj.eradication_result else "") elif field == "nest_status": logger.info("Getting status for observation %s", obj.eradication_result) - # This is handled as requested with eradication result data.append(self.get_status(obj)) elif field == "source_id": data.append(str(obj.source_id) if obj.source_id is not None else "")