2009-05-13 16:54:06 +02:00
|
|
|
"""Implement the ++comments++ traversal namespace. This should return the
|
|
|
|
IDiscussion container for the context, from which traversal will continue
|
|
|
|
into an actual comment object.
|
2009-05-11 18:52:16 +02:00
|
|
|
"""
|
|
|
|
|
2009-05-23 06:55:06 +02:00
|
|
|
from zope.interface import Interface, implements
|
2009-05-23 13:52:57 +02:00
|
|
|
from zope.component import adapts, queryAdapter
|
2009-05-23 06:55:06 +02:00
|
|
|
|
|
|
|
from zope.traversing.interfaces import ITraversable, TraversalError
|
|
|
|
from zope.publisher.interfaces.browser import IBrowserRequest
|
|
|
|
|
|
|
|
from plone.app.discussion.interfaces import IConversation
|
|
|
|
|
2012-01-14 07:35:59 +01:00
|
|
|
|
2009-05-23 06:55:06 +02:00
|
|
|
class ConversationNamespace(object):
|
2009-05-23 13:52:57 +02:00
|
|
|
"""Allow traversal into a conversation via a ++conversation++name
|
|
|
|
namespace. The name is the name of an adapter from context to
|
|
|
|
IConversation. The special name 'default' will be taken as the default
|
|
|
|
(unnamed) adapter. This is to work around a bug in OFS.Traversable which
|
|
|
|
does not allow traversal to namespaces with an empty string name.
|
2009-05-23 06:55:06 +02:00
|
|
|
"""
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2009-05-23 06:55:06 +02:00
|
|
|
implements(ITraversable)
|
|
|
|
adapts(Interface, IBrowserRequest)
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2009-05-23 06:55:06 +02:00
|
|
|
def __init__(self, context, request=None):
|
|
|
|
self.context = context
|
|
|
|
self.request = request
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2009-05-23 06:55:06 +02:00
|
|
|
def traverse(self, name, ignore):
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2009-05-23 13:52:57 +02:00
|
|
|
if name == "default":
|
|
|
|
name = u""
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2009-05-23 13:52:57 +02:00
|
|
|
conversation = queryAdapter(self.context, IConversation, name=name)
|
2009-05-23 06:55:06 +02:00
|
|
|
if conversation is None:
|
2012-01-14 07:35:59 +01:00
|
|
|
raise TraversalError(name) # pragma: no cover
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2009-05-23 13:52:57 +02:00
|
|
|
return conversation
|