From 646df9228cdd7226076ce93fee155ef95023af6a Mon Sep 17 00:00:00 2001 From: Morten Madsen Lyngstad Date: Tue, 29 Jul 2025 12:16:33 +0200 Subject: [PATCH 1/2] Refactor SampleViewset to simplify order ID retrieval and update order of constants for CSV fields --- src/genlab_bestilling/api/constants.py | 2 +- src/genlab_bestilling/api/views.py | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/genlab_bestilling/api/constants.py b/src/genlab_bestilling/api/constants.py index 4b62197f..69036ffd 100644 --- a/src/genlab_bestilling/api/constants.py +++ b/src/genlab_bestilling/api/constants.py @@ -128,9 +128,9 @@ "rerun_date", ), "Terrestrisk": ( - "name", "genlab_id", "guid", + "name", "type.name", "species.name", "location.name", diff --git a/src/genlab_bestilling/api/views.py b/src/genlab_bestilling/api/views.py index 4b78ec2a..dc428377 100644 --- a/src/genlab_bestilling/api/views.py +++ b/src/genlab_bestilling/api/views.py @@ -211,10 +211,9 @@ def get_serializer_class(self) -> type[BaseSerializer]: def get_order_id(self, queryset: QuerySet) -> str: order_id = "unknown_order_id" - first_sample = queryset.first() - if first_sample and first_sample.order and first_sample.order.id: - order_id = str(first_sample.order.id) - + order_id_value = queryset.values_list("order__id", flat=True).first() + if order_id_value: + order_id = str(order_id_value) return order_id @action( From 96a052723bc5b559656ed5e9894cbff046990553 Mon Sep 17 00:00:00 2001 From: Morten Madsen Lyngstad Date: Tue, 29 Jul 2025 13:24:31 +0200 Subject: [PATCH 2/2] Add 'order' field to CSV constants and update LabelCSVSerializer to include location --- src/genlab_bestilling/api/constants.py | 10 +++++----- src/genlab_bestilling/api/serializers.py | 4 ++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/genlab_bestilling/api/constants.py b/src/genlab_bestilling/api/constants.py index 69036ffd..9fba5360 100644 --- a/src/genlab_bestilling/api/constants.py +++ b/src/genlab_bestilling/api/constants.py @@ -199,9 +199,9 @@ } LABEL_CSV_FIELDS_BY_AREA = { - "Akvatisk": ("fish_id", "genlab_id", "guid"), - "Elvemusling": ("fish_id", "genlab_id", "guid"), - "Terrestrisk": ("genlab_id", "guid", "name"), - "MiljøDNA": ("genlab_id", "guid", "name", "location.name"), - "default": ("genlab_id", "guid", "name"), + "Akvatisk": ("fish_id", "genlab_id", "guid", "order"), + "Elvemusling": ("fish_id", "genlab_id", "guid", "order"), + "Terrestrisk": ("genlab_id", "guid", "name", "order"), + "MiljøDNA": ("genlab_id", "guid", "name", "location.name", "order"), + "default": ("genlab_id", "guid", "name", "order"), } diff --git a/src/genlab_bestilling/api/serializers.py b/src/genlab_bestilling/api/serializers.py index 1bdf9ce8..855de4e0 100644 --- a/src/genlab_bestilling/api/serializers.py +++ b/src/genlab_bestilling/api/serializers.py @@ -166,6 +166,8 @@ def get_internal_note(self, obj: Sample) -> str: class LabelCSVSerializer(serializers.ModelSerializer): + location = LocationSerializer(allow_null=True, required=False) + class Meta: model = Sample fields = ( @@ -173,6 +175,8 @@ class Meta: "guid", "name", "fish_id", + "order", + "location", ) def get_fish_id(self, obj: Sample) -> str: