From 1c0a815f4bd702244df79eca63c98e27f5935ec9 Mon Sep 17 00:00:00 2001 From: Pierre Narcisi Date: Mon, 12 Feb 2024 16:52:54 +0100 Subject: [PATCH] feat(checks) manage multi in checks --- .../geonature/core/imports/checks/sql/core.py | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/backend/geonature/core/imports/checks/sql/core.py b/backend/geonature/core/imports/checks/sql/core.py index b0742b0d50..6cbf6e38ce 100644 --- a/backend/geonature/core/imports/checks/sql/core.py +++ b/backend/geonature/core/imports/checks/sql/core.py @@ -33,11 +33,13 @@ def init_rows_validity(imprt): # TODO handle multi columns # Currently if only a multi-fields is mapped, it will be ignored without raising any error. # This is not a very big issue as it is unlikely to map **only** a multi-field. - selected_fields_names = [ - field_name - for field_name, source_field in imprt.fieldmapping.items() - if source_field in imprt.columns - ] + selected_fields_names = [] + for field_name, source_field in imprt.fieldmapping.items(): + if type(source_field) == list: + selected_fields_names.extend(set(source_field) & set(imprt.columns)) + elif source_field in imprt.columns: + selected_fields_names.append(field_name) + for entity in entities: # Select fields associated to this entity *and only to this entity* fields = ( @@ -64,11 +66,13 @@ def check_orphan_rows(imprt): transient_table = imprt.destination.get_transient_table() # TODO: handle multi-source fields # This is actually not a big issue as multi-source fields are unlikely to also be multi-entity fields. - selected_fields_names = [ - field_name - for field_name, source_field in imprt.fieldmapping.items() - if source_field in imprt.columns - ] + selected_fields_names = [] + for field_name, source_field in imprt.fieldmapping.items(): + if type(source_field) == list: + selected_fields_names.extend(set(source_field) & set(imprt.columns)) + elif source_field in imprt.columns: + selected_fields_names.append(field_name) + # Select fields associated to multiple entities AllEntityField = sa.orm.aliased(EntityField) multientity_fields = (