From 204220c575a52b8d60ef057090664438dcaf4354 Mon Sep 17 00:00:00 2001 From: signedav Date: Tue, 27 May 2025 13:55:20 +0200 Subject: [PATCH] fix issue on value relations for enumerations with geopackage (since the t_id is written differently) --- modelbaker/dataobjects/project.py | 21 +++++++----- tests/test_domain_class_relations.py | 2 +- tests/test_projectgen.py | 2 +- ...rojectgen_extension_optimization_smart1.py | 16 ++++++---- ...rojectgen_extension_optimization_smart2.py | 32 ++++++++++--------- 5 files changed, 41 insertions(+), 32 deletions(-) diff --git a/modelbaker/dataobjects/project.py b/modelbaker/dataobjects/project.py index f2290bd..cd30522 100644 --- a/modelbaker/dataobjects/project.py +++ b/modelbaker/dataobjects/project.py @@ -186,7 +186,9 @@ def create( { "AllowMulti": False, "UseCompleter": False, - "Value": "dispName", + "Value": "dispname" + if referenced_layer.provider == "postgres" + else "dispName", "OrderByValue": False if Qgis.QGIS_VERSION_INT >= 34200 else True, # order by value if order by field is not available yet @@ -197,7 +199,9 @@ def create( ) if relation.child_domain_name else "", - "Key": "t_id", + "Key": "t_id" + if referenced_layer.provider == "postgres" + else "T_Id", "NofColumns": 1, "OrderByField": True, "OrderByFieldName": "seq", @@ -238,14 +242,16 @@ def create( "ShowOpenFormButton": False, "AllowNULL": True, "AllowAddFeatures": False, - "FilterExpression": "\"topic\" IN ({}) and attribute(get_feature('{}', 't_id', \"dataset\"), 'datasetname') != '{}'".format( + "FilterExpression": "\"topic\" IN ({}) and attribute(get_feature('{}', '{}', \"dataset\"), 'datasetname') != '{}'".format( ",".join( [f"'{topic}'" for topic in sorted(filter_topics)] ), # create comma separated string - "T_ILI2DB_DATASET" - if referenced_layer.provider == "ogr" - or referenced_layer.provider == "mssql" - else "t_ili2db_dataset", + "t_ili2db_dataset" + if referenced_layer.provider == "postgres" + else "T_ILI2DB_DATASET", + "t_id" + if referenced_layer.provider == "postgres" + else "T_Id", self.context.get("catalogue_datasetname", ""), ) if filter_topics @@ -272,7 +278,6 @@ def create( referencing_layer.setEditorWidgetSetup( rel.referencingFields()[0], editor_widget_setup ) - qgis_project.relationManager().setRelations(qgis_relations) # Set Bag of Enum widget diff --git a/tests/test_domain_class_relations.py b/tests/test_domain_class_relations.py index df5e898..5478b18 100644 --- a/tests/test_domain_class_relations.py +++ b/tests/test_domain_class_relations.py @@ -3998,7 +3998,7 @@ def test_widgets_for_domain_postgis(self): self.assertEqual(type, "ValueRelation") config = field.editorWidgetSetup().config() - assert config["Value"] == "dispName" + assert config["Value"] == "dispname" if Qgis.QGIS_VERSION_INT >= 34200: assert not config["OrderByValue"] diff --git a/tests/test_projectgen.py b/tests/test_projectgen.py index e28076c..16ea09d 100644 --- a/tests/test_projectgen.py +++ b/tests/test_projectgen.py @@ -3298,7 +3298,7 @@ def test_kbs_geopackage_basket_handling(self): ) assert ( map["FilterExpression"] - == f"\"topic\" IN ('KbS_LV95_V1_3.Belastete_Standorte') and attribute(get_feature('T_ILI2DB_DATASET', 't_id', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" + == f"\"topic\" IN ('KbS_LV95_V1_3.Belastete_Standorte') and attribute(get_feature('T_ILI2DB_DATASET', 'T_Id', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" ) # check the display expression of the basket table diff --git a/tests/test_projectgen_extension_optimization_smart1.py b/tests/test_projectgen_extension_optimization_smart1.py index f9875db..f723e5e 100644 --- a/tests/test_projectgen_extension_optimization_smart1.py +++ b/tests/test_projectgen_extension_optimization_smart1.py @@ -352,7 +352,7 @@ def _extopt_staedtische(self, generator, strategy): assert ( map["FilterExpression"] - == f"\"topic\" IN ('Infrastruktur_V1.Strassen') and attribute(get_feature('{self.dataset_tablename}', 't_id', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" + == f"\"topic\" IN ('Infrastruktur_V1.Strassen') and attribute(get_feature('{self.dataset_tablename}', '{self.tid_fieldname}', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" ) # check default value expression @@ -392,9 +392,9 @@ def _extopt_staedtische(self, generator, strategy): map = ews.config() expected_filter_expression = ( - f"\"topic\" IN ('Staedtische_Ortsplanung_V1_1.Freizeit','Staedtische_Ortsplanung_V1_1.Gewerbe') and attribute(get_feature('{self.dataset_tablename}', 't_id', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" + f"\"topic\" IN ('Staedtische_Ortsplanung_V1_1.Freizeit','Staedtische_Ortsplanung_V1_1.Gewerbe') and attribute(get_feature('{self.dataset_tablename}', '{self.tid_fieldname}', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" if strategy == OptimizeStrategy.HIDE - else f"\"topic\" IN ('Kantonale_Ortsplanung_V1_1.Konstruktionen','Ortsplanung_V1_1.Konstruktionen','Staedtische_Ortsplanung_V1_1.Freizeit','Staedtische_Ortsplanung_V1_1.Gewerbe') and attribute(get_feature('{self.dataset_tablename}', 't_id', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" + else f"\"topic\" IN ('Kantonale_Ortsplanung_V1_1.Konstruktionen','Ortsplanung_V1_1.Konstruktionen','Staedtische_Ortsplanung_V1_1.Freizeit','Staedtische_Ortsplanung_V1_1.Gewerbe') and attribute(get_feature('{self.dataset_tablename}', '{self.tid_fieldname}', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" ) assert map["FilterExpression"] == expected_filter_expression @@ -773,7 +773,7 @@ def _extopt_polymorphic(self, generator, strategy): assert ( map["FilterExpression"] - == f"\"topic\" IN ('Infrastruktur_V1.Strassen') and attribute(get_feature('{self.dataset_tablename}', 't_id', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" + == f"\"topic\" IN ('Infrastruktur_V1.Strassen') and attribute(get_feature('{self.dataset_tablename}', '{self.tid_fieldname}', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" ) # check default value expression @@ -812,9 +812,9 @@ def _extopt_polymorphic(self, generator, strategy): map = ews.config() expected_filter_expression = ( - f"\"topic\" IN ('Polymorphic_Ortsplanung_V1_1.Freizeit','Polymorphic_Ortsplanung_V1_1.Gewerbe','Polymorphic_Ortsplanung_V1_1.Hallen','Polymorphic_Ortsplanung_V1_1.IndustrieGewerbe') and attribute(get_feature('{self.dataset_tablename}', 't_id', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" + f"\"topic\" IN ('Polymorphic_Ortsplanung_V1_1.Freizeit','Polymorphic_Ortsplanung_V1_1.Gewerbe','Polymorphic_Ortsplanung_V1_1.Hallen','Polymorphic_Ortsplanung_V1_1.IndustrieGewerbe') and attribute(get_feature('{self.dataset_tablename}', '{self.tid_fieldname}', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" if strategy == OptimizeStrategy.HIDE - else f"\"topic\" IN ('Ortsplanung_V1_1.Konstruktionen','Polymorphic_Ortsplanung_V1_1.Freizeit','Polymorphic_Ortsplanung_V1_1.Gewerbe','Polymorphic_Ortsplanung_V1_1.Hallen','Polymorphic_Ortsplanung_V1_1.IndustrieGewerbe') and attribute(get_feature('{self.dataset_tablename}', 't_id', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" + else f"\"topic\" IN ('Ortsplanung_V1_1.Konstruktionen','Polymorphic_Ortsplanung_V1_1.Freizeit','Polymorphic_Ortsplanung_V1_1.Gewerbe','Polymorphic_Ortsplanung_V1_1.Hallen','Polymorphic_Ortsplanung_V1_1.IndustrieGewerbe') and attribute(get_feature('{self.dataset_tablename}', '{self.tid_fieldname}', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" ) assert map["FilterExpression"] == expected_filter_expression @@ -1199,7 +1199,7 @@ def _extopt_baustruct(self, generator, strategy): assert ( map["FilterExpression"] - == f"\"topic\" IN ('Infrastruktur_V1.Strassen') and attribute(get_feature('{self.dataset_tablename}', 't_id', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" + == f"\"topic\" IN ('Infrastruktur_V1.Strassen') and attribute(get_feature('{self.dataset_tablename}', '{self.tid_fieldname}', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" ) # check default value expression @@ -1323,10 +1323,12 @@ def _set_pg_naming(self, is_pg=True): self.dataset_tablename = "t_ili2db_dataset" self.basket_fieldname = "t_basket" self.type_fieldname = "t_type" + self.tid_fieldname = "t_id" else: self.dataset_tablename = "T_ILI2DB_DATASET" self.basket_fieldname = "T_basket" self.type_fieldname = "T_Type" + self.tid_fieldname = "T_Id" def print_info(self, text): logging.info(text) diff --git a/tests/test_projectgen_extension_optimization_smart2.py b/tests/test_projectgen_extension_optimization_smart2.py index 21accc8..e754a27 100644 --- a/tests/test_projectgen_extension_optimization_smart2.py +++ b/tests/test_projectgen_extension_optimization_smart2.py @@ -432,7 +432,7 @@ def _extopt_staedtische_none(self, generator, strategy): assert ( map["FilterExpression"] - == f"\"topic\" IN ('Infrastruktur_V1.Strassen') and attribute(get_feature('{self.dataset_tablename}', 't_id', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" + == f"\"topic\" IN ('Infrastruktur_V1.Strassen') and attribute(get_feature('{self.dataset_tablename}', '{self.tid_fieldname}', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" ) # check default value expression @@ -470,7 +470,7 @@ def _extopt_staedtische_none(self, generator, strategy): assert ( map["FilterExpression"] - == f"\"topic\" IN ('Kantonale_Ortsplanung_V1_1.Konstruktionen','Ortsplanung_V1_1.Konstruktionen','Staedtische_Ortsplanung_V1_1.Freizeit','Staedtische_Ortsplanung_V1_1.Gewerbe') and attribute(get_feature('{self.dataset_tablename}', 't_id', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" + == f"\"topic\" IN ('Kantonale_Ortsplanung_V1_1.Konstruktionen','Ortsplanung_V1_1.Konstruktionen','Staedtische_Ortsplanung_V1_1.Freizeit','Staedtische_Ortsplanung_V1_1.Gewerbe') and attribute(get_feature('{self.dataset_tablename}', '{self.tid_fieldname}', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" ) # check default value expression @@ -659,7 +659,7 @@ def _extopt_staedtische_group(self, generator, strategy): assert ( map["FilterExpression"] - == f"\"topic\" IN ('Infrastruktur_V1.Strassen') and attribute(get_feature('{self.dataset_tablename}', 't_id', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" + == f"\"topic\" IN ('Infrastruktur_V1.Strassen') and attribute(get_feature('{self.dataset_tablename}', '{self.tid_fieldname}', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" ) # check default value expression @@ -697,7 +697,7 @@ def _extopt_staedtische_group(self, generator, strategy): assert ( map["FilterExpression"] - == f"\"topic\" IN ('Staedtische_Ortsplanung_V1_1.Freizeit','Staedtische_Ortsplanung_V1_1.Gewerbe') and attribute(get_feature('{self.dataset_tablename}', 't_id', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" + == f"\"topic\" IN ('Staedtische_Ortsplanung_V1_1.Freizeit','Staedtische_Ortsplanung_V1_1.Gewerbe') and attribute(get_feature('{self.dataset_tablename}', '{self.tid_fieldname}', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" ) # check default value expression @@ -857,7 +857,7 @@ def _extopt_staedtische_hide(self, generator, strategy): assert ( map["FilterExpression"] - == f"\"topic\" IN ('Infrastruktur_V1.Strassen') and attribute(get_feature('{self.dataset_tablename}', 't_id', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" + == f"\"topic\" IN ('Infrastruktur_V1.Strassen') and attribute(get_feature('{self.dataset_tablename}', '{self.tid_fieldname}', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" ) # check default value expression @@ -895,7 +895,7 @@ def _extopt_staedtische_hide(self, generator, strategy): assert ( map["FilterExpression"] - == f"\"topic\" IN ('Staedtische_Ortsplanung_V1_1.Freizeit','Staedtische_Ortsplanung_V1_1.Gewerbe') and attribute(get_feature('{self.dataset_tablename}', 't_id', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" + == f"\"topic\" IN ('Staedtische_Ortsplanung_V1_1.Freizeit','Staedtische_Ortsplanung_V1_1.Gewerbe') and attribute(get_feature('{self.dataset_tablename}', '{self.tid_fieldname}', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" ) # check default value expression @@ -1314,7 +1314,7 @@ def _extopt_polymorphic_none(self, generator, strategy): assert ( map["FilterExpression"] - == f"\"topic\" IN ('Infrastruktur_V1.Strassen') and attribute(get_feature('{self.dataset_tablename}', 't_id', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" + == f"\"topic\" IN ('Infrastruktur_V1.Strassen') and attribute(get_feature('{self.dataset_tablename}', '{self.tid_fieldname}', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" ) # check default value expression @@ -1352,7 +1352,7 @@ def _extopt_polymorphic_none(self, generator, strategy): assert ( map["FilterExpression"] - == f"\"topic\" IN ('Ortsplanung_V1_1.Konstruktionen','Polymorphic_Ortsplanung_V1_1.Freizeit','Polymorphic_Ortsplanung_V1_1.Gewerbe','Polymorphic_Ortsplanung_V1_1.Hallen','Polymorphic_Ortsplanung_V1_1.IndustrieGewerbe') and attribute(get_feature('{self.dataset_tablename}', 't_id', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" + == f"\"topic\" IN ('Ortsplanung_V1_1.Konstruktionen','Polymorphic_Ortsplanung_V1_1.Freizeit','Polymorphic_Ortsplanung_V1_1.Gewerbe','Polymorphic_Ortsplanung_V1_1.Hallen','Polymorphic_Ortsplanung_V1_1.IndustrieGewerbe') and attribute(get_feature('{self.dataset_tablename}', '{self.tid_fieldname}', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" ) # check default value expression @@ -1583,7 +1583,7 @@ def _extopt_polymorphic_group(self, generator, strategy): assert ( map["FilterExpression"] - == f"\"topic\" IN ('Infrastruktur_V1.Strassen') and attribute(get_feature('{self.dataset_tablename}', 't_id', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" + == f"\"topic\" IN ('Infrastruktur_V1.Strassen') and attribute(get_feature('{self.dataset_tablename}', '{self.tid_fieldname}', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" ) # check default value expression @@ -1621,7 +1621,7 @@ def _extopt_polymorphic_group(self, generator, strategy): assert ( map["FilterExpression"] - == f"\"topic\" IN ('Polymorphic_Ortsplanung_V1_1.Freizeit','Polymorphic_Ortsplanung_V1_1.Gewerbe','Polymorphic_Ortsplanung_V1_1.Hallen','Polymorphic_Ortsplanung_V1_1.IndustrieGewerbe') and attribute(get_feature('{self.dataset_tablename}', 't_id', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" + == f"\"topic\" IN ('Polymorphic_Ortsplanung_V1_1.Freizeit','Polymorphic_Ortsplanung_V1_1.Gewerbe','Polymorphic_Ortsplanung_V1_1.Hallen','Polymorphic_Ortsplanung_V1_1.IndustrieGewerbe') and attribute(get_feature('{self.dataset_tablename}', '{self.tid_fieldname}', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" ) # check default value expression @@ -1832,7 +1832,7 @@ def _extopt_polymorphic_hide(self, generator, strategy): assert ( map["FilterExpression"] - == f"\"topic\" IN ('Infrastruktur_V1.Strassen') and attribute(get_feature('{self.dataset_tablename}', 't_id', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" + == f"\"topic\" IN ('Infrastruktur_V1.Strassen') and attribute(get_feature('{self.dataset_tablename}', '{self.tid_fieldname}', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" ) # check default value expression @@ -1870,7 +1870,7 @@ def _extopt_polymorphic_hide(self, generator, strategy): assert ( map["FilterExpression"] - == f"\"topic\" IN ('Polymorphic_Ortsplanung_V1_1.Freizeit','Polymorphic_Ortsplanung_V1_1.Gewerbe','Polymorphic_Ortsplanung_V1_1.Hallen','Polymorphic_Ortsplanung_V1_1.IndustrieGewerbe') and attribute(get_feature('{self.dataset_tablename}', 't_id', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" + == f"\"topic\" IN ('Polymorphic_Ortsplanung_V1_1.Freizeit','Polymorphic_Ortsplanung_V1_1.Gewerbe','Polymorphic_Ortsplanung_V1_1.Hallen','Polymorphic_Ortsplanung_V1_1.IndustrieGewerbe') and attribute(get_feature('{self.dataset_tablename}', '{self.tid_fieldname}', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" ) # check default value expression @@ -2265,7 +2265,7 @@ def _extopt_baustruct_none(self, generator, strategy): assert ( map["FilterExpression"] - == f"\"topic\" IN ('Infrastruktur_V1.Strassen') and attribute(get_feature('{self.dataset_tablename}', 't_id', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" + == f"\"topic\" IN ('Infrastruktur_V1.Strassen') and attribute(get_feature('{self.dataset_tablename}', '{self.tid_fieldname}', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" ) # check default value expression @@ -2489,7 +2489,7 @@ def _extopt_baustruct_group(self, generator, strategy): assert ( map["FilterExpression"] - == f"\"topic\" IN ('Infrastruktur_V1.Strassen') and attribute(get_feature('{self.dataset_tablename}', 't_id', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" + == f"\"topic\" IN ('Infrastruktur_V1.Strassen') and attribute(get_feature('{self.dataset_tablename}', '{self.tid_fieldname}', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" ) # check default value expression @@ -2673,7 +2673,7 @@ def _extopt_baustruct_hide(self, generator, strategy): assert ( map["FilterExpression"] - == f"\"topic\" IN ('Infrastruktur_V1.Strassen') and attribute(get_feature('{self.dataset_tablename}', 't_id', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" + == f"\"topic\" IN ('Infrastruktur_V1.Strassen') and attribute(get_feature('{self.dataset_tablename}', '{self.tid_fieldname}', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'" ) # check default value expression @@ -2694,10 +2694,12 @@ def _set_pg_naming(self, is_pg=True): self.dataset_tablename = "t_ili2db_dataset" self.basket_fieldname = "t_basket" self.type_fieldname = "t_type" + self.tid_fieldname = "t_id" else: self.dataset_tablename = "T_ILI2DB_DATASET" self.basket_fieldname = "T_basket" self.type_fieldname = "T_Type" + self.tid_fieldname = "T_Id" def print_info(self, text): logging.info(text)