Catch TypeError in indexers if content can not be adapted

Currently plone.app.discussion provides indexers
for IContentish. In these it tries to adapt
the content object to IDiscussion. But an IDiscussion Factory is only
provided for IAnnotatable.
The Criteria are IContentish but not IAnnotatable.
Indexing them fails

svn path=/plone.app.discussion/trunk/; revision=38182
This commit is contained in:
Patrick Gerken 2010-07-21 23:36:16 +00:00
parent 9d8c675e69
commit 94e73b43a7
2 changed files with 27 additions and 7 deletions

View File

@ -1,6 +1,12 @@
Changelog
=========
1.0b6 (unreleased)
------------------
* Catch Type errors in indexers if object can not be adapted to IDiscussion
[do3cc]
1.0b5 (2010-07-16)
------------------

View File

@ -25,25 +25,39 @@ def total_comments(object):
# Total number of comments on a conversation
# Indexers won't work on old discussion items
if object.meta_type != 'Discussion Item':
try:
conversation = IConversation(object)
return conversation.total_comments
except TypeError:
# The item is contentish but nobody
# implemented an adapter for it
pass
@indexer(IContentish, IZCatalog)
def last_comment_date(object):
# Date of the latest comment on a conversation
# Indexers won't work on old discussion items
if object.meta_type != 'Discussion Item':
try:
conversation = IConversation(object)
return conversation.last_comment_date
except TypeError:
# The item is contentish but nobody
# implemented an adapter for it
pass
@indexer(IContentish, IZCatalog)
def commentators(object):
# List of commentators on a conversation
# Indexers won't work on old discussion items
if object.meta_type != 'Discussion Item':
try:
conversation = IConversation(object)
return tuple(conversation.commentators.keys())
except TypeError:
# The item is contentish but nobody
# implemented an adapter for it
pass
# Comment Indexers