From 8ccba358ac11c5aac6f656551fe68adccba97488 Mon Sep 17 00:00:00 2001 From: wlorenzetti Date: Thu, 28 Sep 2023 09:48:27 +0200 Subject: [PATCH 1/3] Add 'help' property to REST API /api/config vector. --- g3w-admin/qdjango/utils/data.py | 1 + g3w-admin/qdjango/vector.py | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/g3w-admin/qdjango/utils/data.py b/g3w-admin/qdjango/utils/data.py index c678ed409..d94bccbb6 100644 --- a/g3w-admin/qdjango/utils/data.py +++ b/g3w-admin/qdjango/utils/data.py @@ -514,6 +514,7 @@ def _getDataColumns(self): 'name': f.name(), 'type': QVariant.typeToName(f.type()).upper() if QVariant.typeToName(f.type()) else None, 'label': f.displayName(), + 'comment': f.comment() }) return columns diff --git a/g3w-admin/qdjango/vector.py b/g3w-admin/qdjango/vector.py index 9e47f9d30..1f04d8c17 100644 --- a/g3w-admin/qdjango/vector.py +++ b/g3w-admin/qdjango/vector.py @@ -297,6 +297,12 @@ def get_forms(self): fields[self.layer_name]['fields'][field] = { 'label': data['label']} + # If fields has a comment, set it as 'help' property + if data['comment']: + fields[self.layer_name]['fields'][field].update({ + "help": data["comment"] + }) + # add widgets if hasattr(self.layer, 'edittypes') and self.layer.edittypes: From b624fdbf821e6fcc767116e89843a9a91b88d3e7 Mon Sep 17 00:00:00 2001 From: wlorenzetti Date: Thu, 28 Sep 2023 09:58:02 +0200 Subject: [PATCH 2/3] Fix for back porting. --- g3w-admin/qdjango/vector.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/g3w-admin/qdjango/vector.py b/g3w-admin/qdjango/vector.py index 1f04d8c17..b3863fa81 100644 --- a/g3w-admin/qdjango/vector.py +++ b/g3w-admin/qdjango/vector.py @@ -298,7 +298,7 @@ def get_forms(self): 'label': data['label']} # If fields has a comment, set it as 'help' property - if data['comment']: + if 'comment' in data and data['comment']: fields[self.layer_name]['fields'][field].update({ "help": data["comment"] }) From 7835cfe0ec0c5659e3a6ee714e8a87fc369e96e9 Mon Sep 17 00:00:00 2001 From: wlorenzetti Date: Thu, 28 Sep 2023 10:17:22 +0200 Subject: [PATCH 3/3] Fix tests. --- g3w-admin/qdjango/tests/test_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/g3w-admin/qdjango/tests/test_utils.py b/g3w-admin/qdjango/tests/test_utils.py index 7cd8b594e..0c1c732da 100644 --- a/g3w-admin/qdjango/tests/test_utils.py +++ b/g3w-admin/qdjango/tests/test_utils.py @@ -221,7 +221,7 @@ def test_layers(self): # check columns # -------------------------------------------------------- - columns_to_check = '[{"name": "ISOCODE", "type": "QSTRING", "label": "ISOCODE"}, {"name": "NAME_LOCAL", "type": "QSTRING", "label": "NAME_LOCAL"}, {"name": "NAME_EN", "type": "QSTRING", "label": "NAME_EN"}, {"name": "CAPITAL_EN", "type": "QSTRING", "label": "CAPITAL_EN"}, {"name": "NAME_DE", "type": "QSTRING", "label": "NAME_DE"}, {"name": "CAPITAL_DE", "type": "QSTRING", "label": "CAPITAL_DE"}, {"name": "NAME_IT", "type": "QSTRING", "label": "NAME_IT"}, {"name": "CAPITAL_IT", "type": "QSTRING", "label": "CAPITAL_IT"}, {"name": "NAME_FR", "type": "QSTRING", "label": "NAME_FR"}, {"name": "CAPITAL_FR", "type": "QSTRING", "label": "CAPITAL_FR"}, {"name": "NAME_BR", "type": "QSTRING", "label": "NAME_BR"}, {"name": "CAPITAL_BR", "type": "QSTRING", "label": "CAPITAL_BR"}, {"name": "NAME_ES", "type": "QSTRING", "label": "NAME_ES"}, {"name": "CAPITAL_ES", "type": "QSTRING", "label": "CAPITAL_ES"}, {"name": "POPULATION", "type": "QLONGLONG", "label": "POPULATION"}, {"name": "AREA_KM2", "type": "QLONGLONG", "label": "AREA_KM2"}, {"name": "ISO_NUM", "type": "INT", "label": "ISO_NUM"}]' + columns_to_check = '[{"name": "ISOCODE", "type": "QSTRING", "label": "ISOCODE", "comment": ""}, {"name": "NAME_LOCAL", "type": "QSTRING", "label": "NAME_LOCAL", "comment": ""}, {"name": "NAME_EN", "type": "QSTRING", "label": "NAME_EN", "comment": ""}, {"name": "CAPITAL_EN", "type": "QSTRING", "label": "CAPITAL_EN", "comment": ""}, {"name": "NAME_DE", "type": "QSTRING", "label": "NAME_DE", "comment": ""}, {"name": "CAPITAL_DE", "type": "QSTRING", "label": "CAPITAL_DE", "comment": ""}, {"name": "NAME_IT", "type": "QSTRING", "label": "NAME_IT", "comment": ""}, {"name": "CAPITAL_IT", "type": "QSTRING", "label": "CAPITAL_IT", "comment": ""}, {"name": "NAME_FR", "type": "QSTRING", "label": "NAME_FR", "comment": ""}, {"name": "CAPITAL_FR", "type": "QSTRING", "label": "CAPITAL_FR", "comment": ""}, {"name": "NAME_BR", "type": "QSTRING", "label": "NAME_BR", "comment": ""}, {"name": "CAPITAL_BR", "type": "QSTRING", "label": "CAPITAL_BR", "comment": ""}, {"name": "NAME_ES", "type": "QSTRING", "label": "NAME_ES", "comment": ""}, {"name": "CAPITAL_ES", "type": "QSTRING", "label": "CAPITAL_ES", "comment": ""}, {"name": "POPULATION", "type": "QLONGLONG", "label": "POPULATION", "comment": ""}, {"name": "AREA_KM2", "type": "QLONGLONG", "label": "AREA_KM2", "comment": ""}, {"name": "ISO_NUM", "type": "INT", "label": "ISO_NUM", "comment": ""}]' self.assertEqual(layer.columns, json.loads(columns_to_check))