2012-01-25 15:57:10 +01:00
|
|
|
==============================================================================
|
|
|
|
Howto override the enable_conversation method.
|
|
|
|
==============================================================================
|
2011-08-09 18:03:52 +02:00
|
|
|
|
2012-01-25 15:57:10 +01:00
|
|
|
plone.app.discussion way to decide if commenting is enabled on a content
|
|
|
|
object can be quite complex and cumbersome due to the need to be backward
|
|
|
|
compatible with the way the old commenting system in Plone (<4.1) worked.
|
|
|
|
|
|
|
|
The comments viewlet calls the enabled method of the ConversationView to
|
|
|
|
decide if the add comment form should show up:
|
|
|
|
|
|
|
|
.. literalinclude:: ../../../plone/app/discussion/browser/conversation.py
|
|
|
|
:language: python
|
|
|
|
:pyobject: ConversationView
|
|
|
|
|
|
|
|
If you want to override this behavior, you just have to create your own enabled method. To do so, we first have to register our custom
|
|
|
|
ConversationView by overriding the existing one in our configure.zcml::
|
2011-08-09 18:03:52 +02:00
|
|
|
|
|
|
|
<configure
|
|
|
|
xmlns="http://namespaces.zope.org/zope"
|
|
|
|
xmlns:browser="http://namespaces.zope.org/browser"
|
2012-01-25 15:57:10 +01:00
|
|
|
i18n_domain="mycustompackage.discussion">
|
|
|
|
|
2011-08-09 18:03:52 +02:00
|
|
|
<!-- Override plone.app.discussion's conversation view -->
|
|
|
|
<browser:page
|
|
|
|
name="conversation_view"
|
|
|
|
for="plone.dexterity.interfaces.IDexterityContent"
|
|
|
|
class=".conversation.ConversationView"
|
|
|
|
permission="zope2.View"
|
|
|
|
/>
|
2012-01-25 15:57:10 +01:00
|
|
|
|
2011-08-09 18:03:52 +02:00
|
|
|
</configure>
|
2012-01-25 15:57:10 +01:00
|
|
|
|
|
|
|
Now we implement the conversation view with a single "enable" method in
|
|
|
|
conversation.py::
|
2011-08-09 18:03:52 +02:00
|
|
|
|
|
|
|
from zope.component import queryUtility
|
2012-01-25 15:57:10 +01:00
|
|
|
|
2011-08-09 18:03:52 +02:00
|
|
|
from plone.registry.interfaces import IRegistry
|
2012-01-25 15:57:10 +01:00
|
|
|
|
2011-08-09 18:03:52 +02:00
|
|
|
from Acquisition import aq_inner
|
2012-01-25 15:57:10 +01:00
|
|
|
|
2011-08-09 18:03:52 +02:00
|
|
|
from Products.CMFCore.utils import getToolByName
|
2012-01-25 15:57:10 +01:00
|
|
|
|
2011-08-09 18:03:52 +02:00
|
|
|
from plone.app.discussion.interfaces import IDiscussionSettings
|
2012-01-25 15:57:10 +01:00
|
|
|
|
|
|
|
|
2011-08-09 18:03:52 +02:00
|
|
|
class ConversationView(object):
|
2012-01-25 15:57:10 +01:00
|
|
|
|
2011-08-09 18:03:52 +02:00
|
|
|
def enabled(self):
|
|
|
|
context = aq_inner(self.context)
|
2012-01-25 15:57:10 +01:00
|
|
|
|
2011-08-09 18:03:52 +02:00
|
|
|
# Fetch discussion registry
|
|
|
|
registry = queryUtility(IRegistry)
|
|
|
|
settings = registry.forInterface(IDiscussionSettings, check=False)
|
2012-01-25 15:57:10 +01:00
|
|
|
|
2011-08-09 18:03:52 +02:00
|
|
|
# Check if discussion is allowed globally
|
|
|
|
if not settings.globally_enabled:
|
|
|
|
return False
|
2012-01-25 15:57:10 +01:00
|
|
|
|
2011-08-09 18:03:52 +02:00
|
|
|
# Check if discussion is allowed on the content object
|
|
|
|
if context.allow_discussion is not None:
|
|
|
|
return context.allow_discussion
|
2012-01-25 15:57:10 +01:00
|
|
|
|
2011-08-09 18:03:52 +02:00
|
|
|
# Check if discussion is allowed on the content type
|
|
|
|
portal_types = getToolByName(self, 'portal_types')
|
|
|
|
document_fti = getattr(portal_types, context.portal_type)
|
|
|
|
return document_fti.getProperty('allow_discussion')
|