From 7f4911a1c3a426d78d1ffad33956d2dc59d6ea19 Mon Sep 17 00:00:00 2001 From: Nicolas Dumazet <nicolas.dumazet@nexedi.com> Date: Thu, 4 Mar 2010 02:10:51 +0000 Subject: [PATCH] unify getDefaultTransformationValue and getDefaultConversionTransformationValue Document getDefaultTransformationValue. git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@33346 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ERP5/Document/Resource.py | 33 +++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/product/ERP5/Document/Resource.py b/product/ERP5/Document/Resource.py index 485765b2ff..0fc084fb59 100644 --- a/product/ERP5/Document/Resource.py +++ b/product/ERP5/Document/Resource.py @@ -282,7 +282,28 @@ class Resource(XMLMatrix, Variated): security.declareProtected(Permissions.AccessContentsInformation, 'getDefaultTransformationValue') - def getDefaultTransformationValue(self, context): + def getDefaultTransformationValue(self, context=None): + """ + If context is None, returns the first available transformation that + use self as a Resource. + + Otherwise, context is used as a Predicate to match Transformations. + If the search returns several candidates due to a relaxed Predicate, + the first item is returned arbitrarily. + """ + if context is None: + transformation_list = self.portal_catalog(portal_type="Transformation", + resource_category_uid=self.getUid()) + if len(transformation_list) > 0: + return transformation_list[0].getObject() + + method = context._getTypeBasedMethod('getDefaultTransformationValue') + if method is not None: + return method(context) + method = self._getTypeBasedMethod('getDefaultTransformationValue') + if method is not None: + return method(context) + transformation_list = self.portal_domains.searchPredicateList(context, portal_type="Transformation") @@ -302,18 +323,14 @@ class Resource(XMLMatrix, Variated): temporary Transformation: one might want for example, for conversion purposes, to ignore some (packaging, wrapping, labelling) components in conversion reports. This method can be used to create a simplified - transformation from the complex transformation returned by - getDefaultTransformationValue + transformation from a complex real-world transformation. """ - method = context._getTypeBasedMethod(\ + method = self._getTypeBasedMethod(\ 'getDefaultConversionTransformationValue') if method is not None: return method() - transformation_list = self.portal_catalog(portal_type="Transformation", - resource_category_uid=self.getUid()) - if len(transformation_list) > 0: - return transformation_list[0].getObject() + return self.getDefaultConversionTransformationValue(context=None) #################################################### -- 2.30.9