From 25c416390e4728374b4eb66b178215ea831e1ab5 Mon Sep 17 00:00:00 2001 From: Riccardo Beltrami Date: Fri, 13 Sep 2024 14:35:28 +0200 Subject: [PATCH 1/3] update html tooltip to handle bootstrap 5 tabs --- lizmap_server/tooltip.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lizmap_server/tooltip.py b/lizmap_server/tooltip.py index 85919526..27c24b87 100755 --- a/lizmap_server/tooltip.py +++ b/lizmap_server/tooltip.py @@ -174,7 +174,7 @@ def create_popup_node_item_from_form( active = visibility h += '\n' + SPACES h += ( - '
  • {}
  • ' + '' ).format(active, regex.sub('_', node.name()), node.name()) headers.append(h) From 40cad6d77813af90b9e8af48c4fcd8d1b02dc959 Mon Sep 17 00:00:00 2001 From: Etienne Trimaille Date: Mon, 23 Sep 2024 12:25:06 +0200 Subject: [PATCH 2/3] Handle both Bootstrap2 and Bootstrap5 versions accoding to CSS_FRAMEWORK=BOOTSTRAP5 --- lizmap_server/get_feature_info.py | 15 ++++++++++++--- lizmap_server/tooltip.py | 23 +++++++++++++++++++---- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/lizmap_server/get_feature_info.py b/lizmap_server/get_feature_info.py index 028521b9..4ee9520f 100755 --- a/lizmap_server/get_feature_info.py +++ b/lizmap_server/get_feature_info.py @@ -80,7 +80,13 @@ def append_maptip(cls, string: str, layer_name: str, feature_id: Union[str, int] @classmethod def feature_list_to_replace( - cls, cfg: dict, project: QgsProject, relation_manager: QgsRelationManager, xml: str) -> List[Result]: + cls, + cfg: dict, + project: QgsProject, + relation_manager: QgsRelationManager, + xml: str, + bootstrap_5: bool + ) -> List[Result]: """ Parse the XML and check for each layer according to the Lizmap CFG file. """ features = [] for layer_name, feature_id in GetFeatureInfoFilter.parse_xml(xml): @@ -120,7 +126,8 @@ def feature_list_to_replace( root = config.invisibleRootContainer() # Need to eval the html_content - html_content = Tooltip.create_popup_node_item_from_form(layer, root, 0, [], '', relation_manager) + html_content = Tooltip.create_popup_node_item_from_form( + layer, root, 0, [], '', relation_manager, bootstrap_5) html_content = Tooltip.create_popup(html_content) # Maybe we can avoid the CSS on all features ? @@ -175,9 +182,11 @@ def responseComplete(self): xml = request.body().data().decode("utf-8") + bootstrap_5 = params.get('CSS_FRAMEWORK', '').upper() == 'BOOTSTRAP5' + # noinspection PyBroadException try: - features = self.feature_list_to_replace(cfg, project, relation_manager, xml) + features = self.feature_list_to_replace(cfg, project, relation_manager, xml, bootstrap_5) except Exception as e: if to_bool(os.getenv("CI")): logger.log_exception(e) diff --git a/lizmap_server/tooltip.py b/lizmap_server/tooltip.py index 27c24b87..5e930af2 100755 --- a/lizmap_server/tooltip.py +++ b/lizmap_server/tooltip.py @@ -60,6 +60,7 @@ def create_popup_node_item_from_form( headers: list, html: str, relation_manager: QgsRelationManager, + bootstrap_5: bool = False, ) -> str: regex = re.compile(r"[^a-zA-Z0-9_]", re.IGNORECASE) a = '' @@ -173,9 +174,22 @@ def create_popup_node_item_from_form( if visibility and not active: active = visibility h += '\n' + SPACES - h += ( - '' - ).format(active, regex.sub('_', node.name()), node.name()) + id_tab = regex.sub('_', node.name()) + if bootstrap_5: + h += ( + f'' + ) + else: + h += ( + f'
  • ' + f'{node.name()}' + f'
  • ' + ) headers.append(h) if lvl > 1: @@ -190,7 +204,8 @@ def create_popup_node_item_from_form( level += 1 for n in node.children(): - h = Tooltip.create_popup_node_item_from_form(layer, n, level, headers, html, relation_manager) + h = Tooltip.create_popup_node_item_from_form( + layer, n, level, headers, html, relation_manager, bootstrap_5) # If it is not root children, add html if lvl > 0: a += h From 472488de4b073b2b365c9c2c914dbff978971ffa Mon Sep 17 00:00:00 2001 From: Etienne Trimaille Date: Mon, 23 Sep 2024 14:46:08 +0200 Subject: [PATCH 3/3] Fix tests about urlencode --- lizmap_server/get_feature_info.py | 2 +- test/test_get_feature_info.py | 2 +- test/utils.py | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lizmap_server/get_feature_info.py b/lizmap_server/get_feature_info.py index 4ee9520f..6b97a25d 100755 --- a/lizmap_server/get_feature_info.py +++ b/lizmap_server/get_feature_info.py @@ -85,7 +85,7 @@ def feature_list_to_replace( project: QgsProject, relation_manager: QgsRelationManager, xml: str, - bootstrap_5: bool + bootstrap_5: bool, ) -> List[Result]: """ Parse the XML and check for each layer according to the Lizmap CFG file. """ features = [] diff --git a/test/test_get_feature_info.py b/test/test_get_feature_info.py index d3bc80b4..e21e32c8 100644 --- a/test/test_get_feature_info.py +++ b/test/test_get_feature_info.py @@ -239,7 +239,7 @@ def test_single_get_feature_info_ascii(client): "FILTER": "accents:\"NAME_1\" = 'Bret\\'agne'", } - rv = client.get(_build_query_string(qs, use_urllib3=True), PROJECT) + rv = client.get(_build_query_string(qs, use_urllib=True), PROJECT) data = _check_request(rv) if Qgis.QGIS_VERSION_INT <= 31700: diff --git a/test/utils.py b/test/utils.py index ec95397d..08c511d5 100644 --- a/test/utils.py +++ b/test/utils.py @@ -8,7 +8,7 @@ from PIL import Image from qgis.server import QgsBufferServerResponse -from urllib3 import request +from urllib.parse import urlencode __copyright__ = 'Copyright 2024, 3Liz' __license__ = 'GPL version 3' @@ -58,10 +58,10 @@ def xpath_text(self, path: str) -> str: return ' '.join(e.text for e in self.xpath(path)) -def _build_query_string(params: dict, use_urllib3: bool=False) -> str: +def _build_query_string(params: dict, use_urllib: bool = False) -> str: """ Build a query parameter from a dictionary. """ - if use_urllib3: - return "?" + request.urlencode(params) + if use_urllib: + return "?" + urlencode(params) query_string = '?' for k, v in params.items():