-
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add endpoint that uses plone.volto indexer
- Loading branch information
1 parent
9bbb1d7
commit 2cbeef5
Showing
4 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<configure | ||
xmlns="http://namespaces.zope.org/zope" | ||
xmlns:plone="http://namespaces.plone.org/plone" | ||
xmlns:zcml="http://namespaces.zope.org/zcml" | ||
> | ||
|
||
<plone:service | ||
method="GET" | ||
factory=".get.BlockTypesGet" | ||
for="zope.interface.Interface" | ||
permission="zope2.View" | ||
name="@blocktypes" | ||
/> | ||
|
||
</configure> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from plone import api | ||
from plone.restapi.services import Service | ||
from collections import Counter | ||
from plone.dexterity.content import get_assignable | ||
|
||
|
||
class BlockTypesGet(Service): | ||
def reply(self): | ||
catalog = api.portal.get_tool(name="portal_catalog") | ||
request_body = self.request.form | ||
result = {} | ||
|
||
if request_body.get("blocktypes") != "": | ||
blocktypes = request_body.get("blocktypes").split(",") | ||
|
||
for blocktype in blocktypes: | ||
brains = catalog.searchResults(block_types=blocktype) | ||
result[blocktype] = Counter() | ||
|
||
for brain in brains: | ||
obj = brain.getObject() | ||
assignable = get_assignable(obj) | ||
|
||
hasBlocksBehavior = bool( | ||
{ | ||
behavior | ||
for behavior in assignable.enumerateBehaviors() | ||
if behavior.name == "volto.blocks" | ||
} | ||
) | ||
|
||
if hasBlocksBehavior: | ||
url = brain.getURL() # or brain.getPath() | ||
|
||
for block in obj.blocks.values(): | ||
if block["@type"] == blocktype: | ||
result[blocktype].update({url: 1}) | ||
|
||
return result |
This file contains 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