Support for Dexterity added.

This commit is contained in:
Timo Stollenwerk
2012-06-30 10:59:49 +02:00
parent 4ef12b189e
commit 0e587a7d85
3 changed files with 112 additions and 1 deletions
@@ -14,10 +14,22 @@ from Products.CMFPlone.interfaces import INonStructuralFolder
from plone.app.discussion.interfaces import IDiscussionSettings
try:
from plone.dexterity.interfaces import IDexterityContent
DEXTERITY_INSTALLED = True
except:
DEXTERITY_INSTALLED = False
class ConversationView(object):
def enabled(self):
if DEXTERITY_INSTALLED and IDexterityContent.providedBy(self.context):
return self._enabled_for_dexterity_types()
else:
return self._enabled_for_archetypes()
def _enabled_for_archetypes(self):
""" Returns True if discussion is enabled for this conversation.
This method checks five different settings in order to figure out if
@@ -94,3 +106,38 @@ class ConversationView(object):
return False
return True
def _enabled_for_dexterity_types(self):
""" Returns True if discussion is enabled for this conversation.
This method checks five different settings in order to figure out if
discussion is enable on a specific content object:
1) Check if discussion is enabled globally in the plone.app.discussion
registry/control panel.
2) Check if the allow_discussion boolean flag on the content object is
set. If it is set to True or False, return the value. If it set to
None, try further.
3) Check if discussion is allowed for the content type.
"""
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 hasattr(context, "allow_discussion"):
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')