[Erp5-dev] patch for ERP.ERP5Site.getDefaultModuleId method

Bartłomiej Górny bartek at erp5.pl
Fri Dec 22 16:12:39 CET 2006


On Thursday 21 of December 2006 17:13, Bartłomiej Górny wrote:
> 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

>
> 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,
> _______________________________________________
> Erp5-dev mailing list
> Erp5-dev at erp5.org
> http://erp5.org/mailman/listinfo/erp5-dev



More information about the Erp5-dev mailing list