Created
May 27, 2025 09:34
-
-
Save mauritsvanrees/91972daa3df18f3eee8cb8bd51bdcee9 to your computer and use it in GitHub Desktop.
Patch for includeSiblings in plone.restapi context navigation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from plone.restapi.services.contextnavigation import get as contextnavigation_get | |
from plone.restapi.services.contextnavigation.get import QueryBuilder | |
import logging | |
logger = logging.getLogger(__name__) | |
contextnavigation_get._orig_extract_data = contextnavigation_get.extract_data | |
def extract_data(schema, raw_data, prefix): | |
data = contextnavigation_get._orig_extract_data(schema, raw_data, prefix) | |
data["includeSiblings"] = raw_data.get(prefix + "includeSiblings", False) | |
return data | |
contextnavigation_get.extract_data = extract_data | |
def querybuilder_call(self): | |
if not self.data.includeSiblings: | |
return self.query | |
# Do not use the bottomLevel as depth. | |
# This undoes https://github.com/plone/plone.restapi/pull/1562 | |
path_query = self.query["path"] | |
if not path_query.get("navtree"): | |
return self.query | |
if path_query.get("depth") not in (self.data.bottomLevel, 999): | |
return self.query | |
path_query.pop("depth") | |
return self.query | |
QueryBuilder.__call__ = querybuilder_call | |
logger.info( | |
"Patched plone.restapi.services.contextnavigation to support includeSiblings." | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment