From 5f2cb7fe596ce5c1b8ee2da6fa0c771dde4ef286 Mon Sep 17 00:00:00 2001
From: Florian Spreckelsen <f.spreckelsen@indiscale.com>
Date: Wed, 22 Jan 2025 13:45:39 +0100
Subject: [PATCH] ENH: Make column descriptions configurable

---
 .../caosdb-server/scripting/bin/bis_utils.py  | 31 ++-----------------
 .../scripting/bin/export_container_csv.py     |  5 ++-
 .../bin/sample_helpers/default_constants.yml  | 27 ++++++++++++++++
 3 files changed, 32 insertions(+), 31 deletions(-)

diff --git a/sample-management-custom/caosdb-server/scripting/bin/bis_utils.py b/sample-management-custom/caosdb-server/scripting/bin/bis_utils.py
index d705030..80165fc 100644
--- a/sample-management-custom/caosdb-server/scripting/bin/bis_utils.py
+++ b/sample-management-custom/caosdb-server/scripting/bin/bis_utils.py
@@ -32,6 +32,8 @@ from caosadvancedtools.serverside.helper import send_mail
 from caoscrawler.config import get_config_setting
 from linkahead import get_entity_by_name
 
+from sample_helpers.utils import CONSTANTS
+
 SPECIAL_TREATMENT_SAMPLE = [
     "BIS ID",
     "Collection",
@@ -82,34 +84,7 @@ IGNORED_COLUMN_NAMES_SAMPLE = [
 ]
 
 
-# This can be used for hard-coded descriptions
-COLUMN_DESCRIPTIONS = {
-    "BIS ID": "An ID generated by the BIS (either integer or URL to this entity). Do not change this column!",
-    "BIS label": "The label automatically assigned by the BIS. Do not change this column.",
-    "Collection": "Collection(s) to which this container or samples belongs (separated by ';')",
-    "Container Contents": "Notes concerning the contents of this container",
-    "Container size": "The size of the container (e.g 81 spaces)",
-    "Container type": "The type of container. Do not change this column.",
-    "Custom label": "Any additional custom label you put on the container",
-    "Date collected start": "The start date in format YYYY-MM-DD",
-    "Date collected stop": "The end date in format YYYY-MM-DD",
-    "Gear configuration": "How gear is configured, meshsize of the net, filter pore size, what kind of trawl",
-    "Latitude start": "Latitude where sampling started; in decimal degrees,use \".\" as decimal sign, use - for S",
-    "Latitude stop": "Latitude where sampling ended; in decimal degrees,use \".\" as decimal sign, use - for S",
-    "Longitude start": "Longitude where sampling started; in decimal degrees,use \".\" as decimal sign, use - for W",
-    "Longitude stop": "Longitude where sampling ended; in decimal degrees,use \".\" as decimal sign, use - for W",
-    "Notes / remarks": "Field for notes",
-    "PDFReport": "A PDF containing additional information on the container or sampe contents",
-    "PI": "The PI (by abbreviation) of the container or sample",
-    "Parent container": "The BIS ID (integer or URL) or name or BIS label of the container where this container is stored.",
-    "Sampling depth start": "The depth in meters where the sampling started as a positive value, not bottom depth",
-    "Sampling depth stop": "The depth in meters where the sampling ended as a positive value,not bottom depth",
-    "Storage ID": "BIS ID of the Container that holds this sample",
-    "Subevent": "Subevent given by D-Ship in Stationlog. Expl. AL123_14-4",
-    "Timezone": "Timezone: Either UTC, CET, .... or in the form +hh[:mm], -hh:[mm].",
-    "Water depth start": "The bottom depth in meters where the sampling started as a positive value",
-    "Water depth stop": "The bottom depth in meters where the sampling ended as a positive value",
-}
+COLUMN_DESCRIPTIONS = CONSTANTS["csv_column_descriptions"]
 
 
 def get_do_not_insert_type_names(override_names: list[str] = []):
diff --git a/sample-management-custom/caosdb-server/scripting/bin/export_container_csv.py b/sample-management-custom/caosdb-server/scripting/bin/export_container_csv.py
index 2ddc7bd..d30e91f 100755
--- a/sample-management-custom/caosdb-server/scripting/bin/export_container_csv.py
+++ b/sample-management-custom/caosdb-server/scripting/bin/export_container_csv.py
@@ -36,7 +36,7 @@ from linkahead.exceptions import (EmptyUniqueQueryError,
 
 from bis_utils import (create_email_with_link_text,
                        get_description_row, get_email_from_username,
-                       send_mail_with_defaults)
+                       get_options_row, send_mail_with_defaults)
 from sample_helpers.utils import (CONSTANTS, get_column_header_name,
                                   get_entity_name)
 
@@ -251,8 +251,7 @@ def retrieve_containers(data):
                 try:
                     container.append(
                         cached_query(
-                            f"FIND RECORD {get_entity_name('container_rt')} WITH id = '{
-                                next_bis_id}'",
+                            f"FIND RECORD {get_entity_name('container_rt')} WITH id = '{next_bis_id}'",
                             unique=True))
                     found_at_least_one_in_range = True
                 except EmptyUniqueQueryError as e:
diff --git a/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/default_constants.yml b/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/default_constants.yml
index ff0dd5a..c773685 100644
--- a/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/default_constants.yml
+++ b/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/default_constants.yml
@@ -18,6 +18,33 @@
 csv_column_names:
   entity_id: "LinkAhead ID"
 
+csv_column_descriptions:
+  LinkAhead ID: "An ID generated by LinkAhead (either integer or URL to this entity). Do not change this column!"
+  container_label: "The label automatically assigned by LinkAhead sample management. Do not change this column."
+  Collection: "Collection(s) to which this container or samples belongs (separated by ';')"
+  Container Contents: "Notes concerning the contents of this container"
+  Container size: "The size of the container (e.g 81 spaces)"
+  Container type: "The type of container. Do not change this column."
+  Custom label: "Any additional custom label you put on the container"
+  Date collected start: "The start date in format YYYY-MM-DD"
+  Date collected stop: "The end date in format YYYY-MM-DD"
+  Gear configuration: "How gear is configured, meshsize of the net, filter pore size, what kind of trawl"
+  Latitude start: "Latitude where sampling started; in decimal degrees,use \".\" as decimal sign, use - for S"
+  Latitude stop: "Latitude where sampling ended; in decimal degrees,use \".\" as decimal sign, use - for S"
+  Longitude start: "Longitude where sampling started; in decimal degrees,use \".\" as decimal sign, use - for W"
+  Longitude stop: "Longitude where sampling ended; in decimal degrees,use \".\" as decimal sign, use - for W"
+  Notes / remarks: "Field for notes"
+  PDFReport: "A PDF containing additional information on the container or sampe contents"
+  PI: "The PI (by abbreviation) of the container or sample"
+  Parent container: "The LinkAhead ID (integer or URL) or name or BIS label of the container where this container is stored."
+  Sampling depth start: "The depth in meters where the sampling started as a positive value, not bottom depth"
+  Sampling depth stop: "The depth in meters where the sampling ended as a positive value,not bottom depth"
+  Storage ID: "LinkAhead ID of the Container that holds this sample"
+  Subevent: "Subevent given by D-Ship in Stationlog. Expl. AL123_14-4"
+  Timezone: "Timezone: Either UTC, CET, .... or in the form +hh[:mm], -hh:[mm]."
+  Water depth start: "The bottom depth in meters where the sampling started as a positive value"
+  Water depth stop: "The bottom depth in meters where the sampling ended as a positive value"
+
 entity_names:
   abbreviation_prop: Abbreviation
   child_container_prop: "Child container"
-- 
GitLab