From 90abe75227913734ca14410ab4c8038f8ee19d8d Mon Sep 17 00:00:00 2001 From: Roman Date: Mon, 25 Mar 2024 14:57:43 +0100 Subject: [PATCH] Handle root path --- .../volto/stickyblocks/restapi/sticky_blocks/get.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/collective/volto/stickyblocks/restapi/sticky_blocks/get.py b/src/collective/volto/stickyblocks/restapi/sticky_blocks/get.py index 1dd966a..d55a708 100644 --- a/src/collective/volto/stickyblocks/restapi/sticky_blocks/get.py +++ b/src/collective/volto/stickyblocks/restapi/sticky_blocks/get.py @@ -33,12 +33,16 @@ def __call__(self, expand=False): def get_sticky_blocks(self): """Get sticky blocks for the current context""" + from functools import cmp_to_key - context_path = "/".join(self.context.getPhysicalPath()) + context_path = "/" + "/".join(self.context.getPhysicalPath()[2:]) - for item in self.get_config(): - if item["rootPath"] == context_path: - return item + matches = sorted( + [i for i in self.get_config() if context_path.startswith(i["rootPath"])], + key=cmp_to_key(lambda a, b: len(a) > len(b)), + ) + + return matches and matches[-1] or [] def get_config(self): return json.loads(