Split too complex _enabled_for_archetypes.

This commit is contained in:
Maurits van Rees 2016-06-10 03:40:07 +02:00 committed by Gil Forcada
parent d496dfdddc
commit 1e9909ab6f
2 changed files with 21 additions and 19 deletions

View File

@ -22,6 +22,8 @@ Bug fixes:
Bug fixes: Bug fixes:
- Cleaned code from flake8 errors. [maurits]
- Reset the required setting of the author_email widget each time. - Reset the required setting of the author_email widget each time.
Otherwise, the email field might get set to required when an Otherwise, the email field might get set to required when an
anonymous user visits, and then remain required when an anonymous user visits, and then remain required when an
@ -29,7 +31,6 @@ Bug fixes:
user to fill in the form without validation error. Or when in the user to fill in the form without validation error. Or when in the
control panel the field is set as not required anymore, that change control panel the field is set as not required anymore, that change
would have no effect until the instance was restarted. [maurits] would have no effect until the instance was restarted. [maurits]
- Cleaned code from flake8 errors. [maurits]
2.4.14 (2016-06-06) 2.4.14 (2016-06-06)

View File

@ -19,6 +19,20 @@ except ImportError:
DEXTERITY_INSTALLED = False DEXTERITY_INSTALLED = False
def traverse_parents(context):
# Run through the aq_chain of obj and check if discussion is
# enabled in a parent folder.
for obj in aq_chain(context):
if not IPloneSiteRoot.providedBy(obj):
obj_is_folderish = IFolderish.providedBy(obj)
obj_is_stuctural = not INonStructuralFolder.providedBy(obj)
if (obj_is_folderish and obj_is_stuctural):
flag = getattr(obj, 'allow_discussion', None)
if flag is not None:
return flag
return None
class ConversationView(object): class ConversationView(object):
def enabled(self): def enabled(self):
@ -31,14 +45,14 @@ class ConversationView(object):
""" Returns True if discussion is enabled for this conversation. """ Returns True if discussion is enabled for this conversation.
This method checks five different settings in order to figure out if This method checks five different settings in order to figure out if
discussion is enable on a specific content object: discussion is enabled on a specific content object:
1) Check if discussion is enabled globally in the plone.app.discussion 1) Check if discussion is enabled globally in the plone.app.discussion
registry/control panel. registry/control panel.
2) If the current content object is a folder, always return 2) If the current content object is a folder, always return
False, since we don't allow comments on a folder. This False, since we don't allow comments on a folder. This
setting is used to allow/ disallow comments for all content setting is used to allow / disallow comments for all content
objects inside a folder, not for the folder itself. objects inside a folder, not for the folder itself.
3) Check if the allow_discussion boolean flag on the content object is 3) Check if the allow_discussion boolean flag on the content object is
@ -63,22 +77,9 @@ class ConversationView(object):
# Always return False if object is a folder # Always return False if object is a folder
context_is_folderish = IFolderish.providedBy(context) context_is_folderish = IFolderish.providedBy(context)
context_is_structural = not INonStructuralFolder.providedBy(context) if context_is_folderish:
if (context_is_folderish and context_is_structural): if not INonStructuralFolder.providedBy(context):
return False return False
def traverse_parents(context):
# Run through the aq_chain of obj and check if discussion is
# enabled in a parent folder.
for obj in aq_chain(context):
if not IPloneSiteRoot.providedBy(obj):
obj_is_folderish = IFolderish.providedBy(obj)
obj_is_stuctural = not INonStructuralFolder.providedBy(obj)
if (obj_is_folderish and obj_is_stuctural):
flag = getattr(obj, 'allow_discussion', None)
if flag is not None:
return flag
return None
# If discussion is disabled for the object, bail out # If discussion is disabled for the object, bail out
obj_flag = getattr(aq_base(context), 'allow_discussion', None) obj_flag = getattr(aq_base(context), 'allow_discussion', None)