Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions modelbaker/dataobjects/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_domain_class_relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_projectgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 9 additions & 7 deletions tests/test_projectgen_extension_optimization_smart1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
32 changes: 17 additions & 15 deletions tests/test_projectgen_extension_optimization_smart2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down