From 405ecc1268038ccafc908d2617bf119cb8ef7cd2 Mon Sep 17 00:00:00 2001 From: Hanno Schlichting Date: Thu, 28 Jan 2010 13:44:56 +0000 Subject: [PATCH] Added an optional conversationCanonicalAdapterFactory showing how to share comments across all translations with LinguaPlone, by storing and retrieving the conversation from the canonical object. svn path=/plone.app.discussion/trunk/; revision=33546 --- docs/HISTORY.txt | 4 ++++ plone/app/discussion/conversation.py | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/docs/HISTORY.txt b/docs/HISTORY.txt index 5f6ece1..5bef8cb 100644 --- a/docs/HISTORY.txt +++ b/docs/HISTORY.txt @@ -4,6 +4,10 @@ Changelog 1.0b3 (XXXX-XX-XX) ------------------ +* Added an optional conversationCanonicalAdapterFactory showing how to share + comments across all translations with LinguaPlone, by storing and retrieving + the conversation from the canonical object. [hannosch] + * Play by the Plone 3.3+ rules and use the INavigationRoot as a base for the moderation view. [hannosch] * Added a commentTitle CSS class to the comment titles. [hannosch] * Update message ids to match their real text. [hannosch] diff --git a/plone/app/discussion/conversation.py b/plone/app/discussion/conversation.py index 68f8c8d..f3bb627 100644 --- a/plone/app/discussion/conversation.py +++ b/plone/app/discussion/conversation.py @@ -341,6 +341,7 @@ class Conversation(Traversable, Persistent, Explicit): for k, v in self._comments.iteritems(): yield (k, v.__of__(self),) + @implementer(IConversation) @adapter(IAnnotatable) def conversationAdapterFactory(content): @@ -356,6 +357,26 @@ def conversationAdapterFactory(content): conversation = annotions[ANNOTATION_KEY] return conversation.__of__(content) + +try: + from Products.LinguaPlone.interfaces import ITranslatable +except ImportError: + pass +else: + @implementer(IConversation) + @adapter(IAnnotatable) + def conversationCanonicalAdapterFactory(content): + """Adapter factory to fetch the default conversation from annotations. + Will create the conversation if it does not exist. + + This adapter will fetch and store all comments on the canonical object, + so that comments will be shared across all translations. + """ + if ITranslatable.providedBy(content): + content = content.getCanonical() + return conversationAdapterFactory(content) + + class ConversationReplies(object): """An IReplies adapter for conversations.