-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add indexer to index authors from a blog post (#52)
* add indexer to index authors from a blog post * update install test * news
- Loading branch information
Showing
8 changed files
with
64 additions
and
2 deletions.
There are no files selected for viewing
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 @@ | ||
- Add indexer for indexing authors from a blog post [@jonaspiterek] |
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 |
---|---|---|
|
@@ -11,4 +11,9 @@ | |
name="blog_uid" | ||
/> | ||
|
||
<adapter | ||
factory=".post.post_authors" | ||
name="post_authors" | ||
/> | ||
|
||
</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 |
---|---|---|
@@ -1,9 +1,26 @@ | ||
from collective.blog.content.post import IPost | ||
from collective.blog.content.post import Post | ||
from plone import api | ||
from plone.indexer import indexer | ||
|
||
|
||
@indexer(IPost) | ||
def blog_post_indexer(obj: Post): | ||
"""Return blog uuid.""" | ||
return obj.blog_uid() | ||
|
||
|
||
@indexer(IPost) | ||
def post_authors(obj: Post): | ||
"""Returns the authors of a blog post.""" | ||
authors = [] | ||
uids = obj.creators | ||
for uid in uids: | ||
searchResult = api.content.find(portal_type="Author", UID=uid) | ||
if len(searchResult) > 0: | ||
author = searchResult[0].getObject() | ||
|
||
if author is not None: | ||
authors.append(author.title) | ||
|
||
return authors |
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
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
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
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 @@ | ||
from collective.blog import logger | ||
from plone import api | ||
from Products.GenericSetup.tool import SetupTool | ||
|
||
|
||
def recatalog_post_authors(setup_tool: SetupTool): | ||
"""Recatalog Posts.""" | ||
with api.env.adopt_roles(["Manager"]): | ||
brains = api.content.find(portal_type=["Post"]) | ||
total = len(brains) | ||
logger.info(f"Recatalog {total} items") | ||
for brain in brains: | ||
obj = brain.getObject() | ||
obj.reindexObject(idxs=["post_authors"]) | ||
logger.info("Reindexed post_authors") |
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