Commit def6774e authored by Vincent Pelletier's avatar Vincent Pelletier

fixup! ERP5Site: Improve getDefaultModule*.

parent afb722a0
...@@ -1523,7 +1523,7 @@ class ERP5Site(FolderMixIn, CMFSite, CacheCookieMixin): ...@@ -1523,7 +1523,7 @@ class ERP5Site(FolderMixIn, CMFSite, CacheCookieMixin):
be created. be created.
""" """
try: try:
module = self.getDefaultModuleValue(portal_type, only_visible=False) module = self.getDefaultModuleValue(portal_type, only_visible=only_visible)
except ValueError: except ValueError:
if default is MARKER: if default is MARKER:
raise ValueError('Unable to find module for portal_type: ' + portal_type) raise ValueError('Unable to find module for portal_type: ' + portal_type)
...@@ -1556,9 +1556,10 @@ class ERP5Site(FolderMixIn, CMFSite, CacheCookieMixin): ...@@ -1556,9 +1556,10 @@ class ERP5Site(FolderMixIn, CMFSite, CacheCookieMixin):
portal_type in x.getVisibleAllowedContentTypeList() portal_type in x.getVisibleAllowedContentTypeList()
) )
else: else:
getTypeInfo = self.portal_types.getTypeInfo
allowed = lambda x: ( allowed = lambda x: (
x is not None and x is not None and
portal_type in (y.id for y in x.allowedContentTypes()) portal_type in getTypeInfo(x).getTypeAllowedContentTypeList()
) )
expected_module_id += '_module' expected_module_id += '_module'
module = self._getOb(expected_module_id, None) module = self._getOb(expected_module_id, None)
...@@ -1583,12 +1584,9 @@ class ERP5Site(FolderMixIn, CMFSite, CacheCookieMixin): ...@@ -1583,12 +1584,9 @@ class ERP5Site(FolderMixIn, CMFSite, CacheCookieMixin):
For backward-compatibility. For backward-compatibility.
Use getDefaultModuleValue (beware of slight "default" semantic change !). Use getDefaultModuleValue (beware of slight "default" semantic change !).
""" """
try: module_id = self.getDefaultModuleId(portal_type, default)
return self.getDefaultModuleValue(portal_type) if module_id:
except ValueError: return getattr(self, module_id, None)
if default is MARKER:
raise ValueError('Unable to find module for portal_type: ' + portal_type)
return self._getOb(default)
security.declareProtected(Permissions.AddPortalContent, 'newContent') security.declareProtected(Permissions.AddPortalContent, 'newContent')
def newContent(self, id=None, portal_type=None, **kw): def newContent(self, id=None, portal_type=None, **kw):
......
...@@ -403,6 +403,11 @@ class TestERP5Core(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -403,6 +403,11 @@ class TestERP5Core(ERP5TypeTestCase, ZopeTestCase.Functional):
module, module,
portal.getDefaultModule(portal_type, default=module_id) portal.getDefaultModule(portal_type, default=module_id)
) )
self.assertIs(
None,
portal.getDefaultModule(portal_type, default=None)
)
self.assertIs( self.assertIs(
default, default,
portal.getDefaultModuleValue(portal_type, default=default), portal.getDefaultModuleValue(portal_type, default=default),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment