Skip to content

Commit

Permalink
aug release (#218)
Browse files Browse the repository at this point in the history
  • Loading branch information
mainlyIt authored Oct 13, 2024
1 parent 1cffd5c commit 25723ad
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 15 deletions.
9 changes: 6 additions & 3 deletions src/components/ObservationDetailsComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ export default {
const eradicationStatusText = computed(() => {
const result = selectedObservation.value?.eradication_result;
if (result === 'successful') {
if (result && result !== null) {
return 'Bestreden';
} else {
return 'Niet bestreden';
Expand All @@ -541,7 +541,7 @@ export default {
const eradicationStatusClass = computed(() => {
const result = selectedObservation.value?.eradication_result;
if (result === 'successful') {
if (result && result !== null) {
return 'bg-success';
} else {
return 'bg-danger';
Expand Down Expand Up @@ -643,7 +643,9 @@ export default {
'eradication_problems', 'eradication_notes', 'eradication_product'
];
const hasEradicationData = eradicationFields.some(field => editableObservation.value[field]);
if (editableObservation.value.eradication_date) {
editableObservation.value.eradication_date += "T00:00:00";
}
if (hasEradicationData && !editableObservation.value.eradication_result) {
eradicationResultError.value = 'Resultaat is verplicht wanneer andere bestrijdingsgegevens zijn ingevuld.';
throw new Error('Validation failed');
Expand Down Expand Up @@ -705,6 +707,7 @@ export default {
editableObservation.value = { ...newVal };
editableObservation.value.observation_datetime = formatToDatetimeLocal(selectedObservation.value.observation_datetime);
editableObservation.value.eradication_date = formatToDate(selectedObservation.value.eradication_date);
//editableObservation.value.eradication_date = formatToDate(newVal.eradication_date);
}
}, { immediate: true });
watch(selectedObservation, resetEditableObservation, { immediate: true });
Expand Down
6 changes: 1 addition & 5 deletions src/stores/vespaStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,8 @@ export const useVespaStore = defineStore('vespaStore', {
observation.observation_datetime = this.formatToISO8601(observation.observation_datetime);
}
if (observation.eradication_date) {
observation.eradication_date = this.formatDateWithoutTime(observation.eradication_date);


observation.eradication_date = this.formatDateWithEndOfDayTime(observation.eradication_date);
}


try {
const response = await ApiService.patch(`/observations/${observation.id}/`, observation);
if (response.status === 200) {
Expand Down
30 changes: 30 additions & 0 deletions vespadb/management/commands/clear_observations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""Management command to delete all records from the database."""

from typing import Any

from django.core.management.base import BaseCommand
from django.db import transaction

from vespadb.observations.models import Observation


class Command(BaseCommand):
"""Delete all records from the database."""

help = "Delete all records from the database"

def handle(self, *args: Any, **options: Any) -> None:
"""Handle the command to delete all records."""
confirm = input(
"Are you sure you want to delete all records from the database? This action cannot be undone! (yes/no): "
)

if confirm.lower() not in {"yes", "y"}:
self.stdout.write(self.style.WARNING("Aborted. No records have been deleted."))
return

with transaction.atomic():
count, _ = Observation.objects.all().delete()
self.stdout.write(self.style.SUCCESS(f"Deleted {count} records from the Observation model."))

self.stdout.write(self.style.SUCCESS("Operation completed."))
4 changes: 0 additions & 4 deletions vespadb/observations/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"nest_location",
"nest_type",
"observation_datetime",
"wn_cluster_id",
"modified_by",
"created_by",
"province",
Expand All @@ -44,9 +43,6 @@
"images",
"public_domain",
"municipality_name",
"visible",
"reserved_by",
"reserved_by_first_name",
"modified_by_first_name",
"created_by_first_name",
"wn_notes",
Expand Down
30 changes: 27 additions & 3 deletions vespadb/observations/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,13 +642,37 @@ def export(self, request: Request) -> Response:

paginator = Paginator(queryset, 1000)
serialized_data = []
errors = []

for page_number in paginator.page_range:
page = paginator.page(page_number)
serializer = serializer_class(page, many=True, context=serializer_context)
serialized_data.extend(serializer.data)
try:
serializer = serializer_class(page, many=True, context=serializer_context)
serialized_data.extend(serializer.data)
except ValidationError:
logger.exception(f"Validation error in page {page_number}, processing individually.")
for obj in page.object_list:
serializer = serializer_class(obj, context=serializer_context)
try:
serializer.is_valid(raise_exception=True)
serialized_data.append(serializer.data)
except ValidationError as e:
errors.append({
"id": obj.id,
"error": str(e),
"data": serializer.data,
})

if errors:
logger.error(f"Errors during export: {errors}")

if export_format == "json":
return JsonResponse(serialized_data, safe=False, json_dumps_params={"indent": 2})
response_data = {
"data": serialized_data,
"errors": errors,
}
return JsonResponse(response_data, safe=False, json_dumps_params={"indent": 2})

if export_format == "csv":
response = HttpResponse(content_type="text/csv")
response["Content-Disposition"] = f'attachment; filename="observations_export_{user.username}.csv"'
Expand Down

0 comments on commit 25723ad

Please sign in to comment.