Commit cfcd1fac authored by Romain Courteaud's avatar Romain Courteaud

Do not use hasattr.

getDefaultModuleId should only return module ID (and not portal id in some
cases).


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@15223 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent fc4e8f1d
...@@ -928,37 +928,39 @@ class ERP5Site(FolderMixIn, CMFSite): ...@@ -928,37 +928,39 @@ class ERP5Site(FolderMixIn, CMFSite):
'getDefaultModuleId') 'getDefaultModuleId')
def getDefaultModuleId(self, portal_type, default=MARKER): def getDefaultModuleId(self, portal_type, default=MARKER):
""" """
Return default module id where a object with portal_type can Return default module id where a object with portal_type can
be created. be created.
""" """
# first try to find by naming convention
module_name = portal_type.lower().replace(' ','_')
portal_object = self portal_object = self
if hasattr(portal_object, module_name): module_id = None
return module_name # first try to find by naming convention
module_name += '_module' expected_module_id = portal_type.lower().replace(' ','_')
if hasattr(portal_object, module_name): if portal_object._getOb(expected_module_id, None) is not None:
return module_name module_id = expected_module_id
expected_module_id += '_module'
if portal_object._getOb(expected_module_id, None) is not None:
module_id = expected_module_id
# then look for module where the type is allowed # then look for module where the type is allowed
module_name = None for expected_module_id in portal_object.objectIds(spec=('ERP5 Folder',)):
modlist = [m for m in self.objectIds() if m.endswith('module')] module = portal_object._getOb(expected_module_id, None)
for mod in modlist: if module is not None:
module = self.restrictedTraverse(mod, None) if portal_type in self.portal_types[module.getPortalType()].\
if module is None: # we can't access this one allowed_content_types:
continue module_id = expected_module_id
if portal_type in self.portal_types[module.getPortalType()].allowed_content_types: break
module_name = mod
break if module_id is None:
if module_name is not None: if default is not MARKER:
return module_name return default
if default is not MARKER: else:
return default # now we fail
# now we fail LOG('ERP5Site, getDefaultModuleId', 0,
LOG('ERP5Site, getDefaultModuleId', 0, 'Unable to find default module for portal_type: %s' % \
'Unable to find default module for portal_type: %s' % \ portal_type)
portal_type) raise ValueError, 'Unable to find module for portal_type: %s' % \
raise ValueError, 'Unable to find module for portal_type: %s' % \ portal_type
portal_type
return module_id
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getDefaultModule') 'getDefaultModule')
......
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