Skip to content

Commit

Permalink
Merge pull request #270 from inbo/dec-release
Browse files Browse the repository at this point in the history
dec release 1
  • Loading branch information
mainlyIt authored Dec 16, 2024
2 parents dddd180 + 16d6733 commit 4886e91
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 22 deletions.
38 changes: 29 additions & 9 deletions src/components/FilterComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,35 @@
</v-autocomplete>
</div>
<div class="col-12">
<v-text-field v-model="minDate" label="Observaties vanaf" prepend-icon="mdi-calendar" readonly
@click="toggleMenu1"></v-text-field>
<v-date-picker v-model="minDate" v-show="menu1" @input="closeMenu1" @change="closeMenu1"></v-date-picker>
</div>
<div class="col-12">
<v-text-field v-model="maxDate" label="Observaties tot" prepend-icon="mdi-calendar" readonly
@click="toggleMenu2"></v-text-field>
<v-date-picker v-model="maxDate" v-show="menu2" @input="closeMenu2" @change="closeMenu2"></v-date-picker>
</div>
<v-text-field
:model-value="formattedMinDate"
label="Observaties vanaf"
prepend-icon="mdi-calendar"
readonly
@click="toggleMenu1"
></v-text-field>
<v-date-picker
v-model="minDate"
v-show="menu1"
@input="closeMenu1"
@change="closeMenu1"
></v-date-picker>
</div>
<div class="col-12">
<v-text-field
:model-value="formattedMaxDate"
label="Observaties tot"
prepend-icon="mdi-calendar"
readonly
@click="toggleMenu2"
></v-text-field>
<v-date-picker
v-model="maxDate"
v-show="menu2"
@input="closeMenu2"
@change="closeMenu2"
></v-date-picker>
</div>
<div class="col-12">
<v-autocomplete v-model="selectedNestType" :items="nestType.length ? nestType.map(nesttype => ({
title: nesttype.name,
Expand Down
2 changes: 1 addition & 1 deletion src/components/ObservationDetailsComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@
</div>
</div>
<div class="row mb-2">
<label class="col-4 col-form-label">Opmerking validator</label>
<label class="col-4 col-form-label">Opmerking</label>
<div class="col-8">
<p class="form-control-plaintext">{{ selectedObservation.notes }}</p>
</div>
Expand Down
4 changes: 4 additions & 0 deletions src/stores/vespaStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
20 changes: 13 additions & 7 deletions vespadb/observations/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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",
Expand All @@ -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."
)
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 8 additions & 5 deletions vespadb/observations/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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":
Expand All @@ -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 "")
Expand Down

0 comments on commit 4886e91

Please sign in to comment.