plone.app.discussion/docs/source/howtos/howto_override_enable_conve...

61 lines
2.0 KiB
Plaintext
Raw Normal View History

configure.zcml::
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser"
xmlns:plone="http://namespaces.plone.org/plone"
xmlns:grok="http://namespaces.zope.org/grok"
i18n_domain="freitag.behavior.allowdiscussion">
<!-- Override plone.app.discussion's conversation view -->
<browser:page
name="conversation_view"
for="plone.dexterity.interfaces.IDexterityContent"
class=".conversation.ConversationView"
permission="zope2.View"
/>
</configure>
conversation.py
from zope.component import queryUtility
from plone.registry.interfaces import IRegistry
from Acquisition import aq_base
from Acquisition import aq_chain
from Acquisition import aq_inner
from Products.CMFCore.utils import getToolByName
from Products.CMFCore.interfaces import IFolderish
from Products.CMFPlone.interfaces import IPloneSiteRoot
from Products.CMFPlone.interfaces import INonStructuralFolder
from plone.app.discussion.interfaces import IDiscussionSettings
class ConversationView(object):
def enabled(self):
context = aq_inner(self.context)
# Fetch discussion registry
registry = queryUtility(IRegistry)
settings = registry.forInterface(IDiscussionSettings, check=False)
# Check if discussion is allowed globally
if not settings.globally_enabled:
return False
# Check if discussion is allowed on the content object
if context.allow_discussion is not None:
return context.allow_discussion
# 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')