2016-02-05 01:39:53 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
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 plone.app.discussion.interfaces import IConversation
|
2015-05-03 08:16:39 +02:00
|
|
|
from zope.component import adapts
|
|
|
|
from zope.component import queryAdapter
|
2016-07-05 23:12:08 +02:00
|
|
|
from zope.interface import implementer
|
2015-05-03 08:16:39 +02:00
|
|
|
from zope.interface import Interface
|
|
|
|
from zope.publisher.interfaces.browser import IBrowserRequest
|
|
|
|
from zope.traversing.interfaces import ITraversable
|
|
|
|
from zope.traversing.interfaces import TraversalError
|
2009-05-23 06:55:06 +02:00
|
|
|
|
2012-01-14 07:35:59 +01:00
|
|
|
|
2016-07-05 23:12:08 +02:00
|
|
|
@implementer(ITraversable)
|
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
|
|
|
"""
|
|
|
|
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
|
|
|
|
2016-02-05 01:39:53 +01: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
|