Discussion:
[Erp5-dev] patch for ERP.ERP5Site.getDefaultModuleId method
Bartłomiej Górny
2006-12-21 16:13:49 UTC
Permalink
Hello

I crafted out a "less dummy" method for finding the right module for creating
a portal type - any objections against commiting it?

Index: ERP5/ERP5Site.py
===================================================================
--- ERP5/ERP5Site.py (r??vision 11733)
+++ ERP5/ERP5Site.py (copie de travail)
@@ -816,19 +816,33 @@
Return default module id where a object with portal_type can
be created.
"""
- # Very dummy method, but it works with today name convention.
+ # first try to find by naming convention
module_name = portal_type.lower().replace(' ','_')
portal_object = self
- if not hasattr(portal_object, module_name):
- module_name += '_module'
- if not hasattr(portal_object, module_name):
- if default is not MARKER:
- return default
- LOG('ERP5Site, getDefaultModuleId', 0,
- 'Unable to find default module for portal_type: %s' % \
- portal_type)
- raise ValueError, 'Unable to find module for portal_type: %s' % \
- portal_type
+ if hasattr(portal_object, module_name):
+ return module_name
+ module_name += '_module'
+ if hasattr(portal_object, module_name):
+ return module_name
+ # then look for module where the type is allowed
+ module_name=MARKER
+ modlist=[m for m in self.objectIds() if m.endswith('module')]
+ for mod in modlist:
+ module=self.restrictedTraverse(mod,MARKER)
+ if module is MARKER: # we can't access this one
+ continue
+ if portal_type in
self.portal_types[module.getPortalType()].allowed_conte
nt_types:
+ module_name=mod
+ break
+ if module_name is not MARKER:
+ return module_name
+ if default is not MARKER:
+ return default
+ LOG('ERP5Site, getDefaultModuleId', 0,
+ 'Unable to find default module for portal_type: %s' % \
+ portal_type)
+ raise ValueError, 'Unable to find module for portal_type: %s' % \
+ portal_type
return module_name

security.declareProtected(Permissions.AccessContentsInformation,
Bartłomiej Górny
2006-12-22 15:12:39 UTC
Permalink
Post by Bartłomiej Górny
Hello
I crafted out a "less dummy" method for finding the right module for
creating a portal type - any objections against commiting it?
No objections were raised, so there it goes to svn.

Bartek
Post by Bartłomiej Górny
Index: ERP5/ERP5Site.py
===================================================================
--- ERP5/ERP5Site.py (r??vision 11733)
+++ ERP5/ERP5Site.py (copie de travail)
@@ -816,19 +816,33 @@
Return default module id where a object with portal_type can
be created.
"""
- # Very dummy method, but it works with today name convention.
+ # first try to find by naming convention
module_name = portal_type.lower().replace(' ','_')
portal_object = self
- module_name += '_module'
- return default
- LOG('ERP5Site, getDefaultModuleId', 0,
- 'Unable to find default module for portal_type: %s' % \
- portal_type)
- raise ValueError, 'Unable to find module for portal_type: %s' % \
- portal_type
+ return module_name
+ module_name += '_module'
+ return module_name
+ # then look for module where the type is allowed
+ module_name=MARKER
+ modlist=[m for m in self.objectIds() if m.endswith('module')]
+ module=self.restrictedTraverse(mod,MARKER)
+ if module is MARKER: # we can't access this one
+ continue
+ if portal_type in
self.portal_types[module.getPortalType()].allowed_conte
+ module_name=mod
+ break
+ return module_name
+ return default
+ LOG('ERP5Site, getDefaultModuleId', 0,
+ 'Unable to find default module for portal_type: %s' % \
+ portal_type)
+ raise ValueError, 'Unable to find module for portal_type: %s' % \
+ portal_type
return module_name
security.declareProtected(Permissions.AccessContentsInformation,
_______________________________________________
Erp5-dev mailing list
Erp5-dev at erp5.org
http://erp5.org/mailman/listinfo/erp5-dev
Loading...