Commit 2216ef53 authored by Sebastien Robin's avatar Sebastien Robin Committed by Cédric Le Ninivin

mrp: use predicates to find out transformations corresponding to a context

Since predicate could match any property, the transformation corresponding to a line might
change upon the change of any property. Make sure the interaction take into account any property
parent bd804786
......@@ -5,14 +5,9 @@ if include_empty:
result.append(('',''))
if resource is not None:
portal = context.getPortalObject()
kw = {'validation_state': '!=invalidated'} if skip_invalidated else {}
result.extend((transformation.title, transformation.relative_url)
for transformation in portal.portal_catalog(
select_list=('title', 'relative_url'),
portal_type=portal.getPortalTransformationTypeList(),
strict_resource_uid=resource.getUid(),
sort_on=('title', 'relative_url'),
**kw))
result.extend([(x.getTitle(), x.getRelativeUrl()) for x in resource.searchTransformationList(context,
**kw)])
portal = context.getPortalObject()
return result
......@@ -56,9 +56,7 @@
<key> <string>method_id</string> </key>
<value>
<list>
<string>_setResource.*</string>
<string>_setStartDate</string>
<string>_setStopDate</string>
<string>_set.*</string>
</list>
</value>
</item>
......
......@@ -270,10 +270,20 @@ class Resource(XMLObject, XMLMatrix, VariatedMixin):
def getDefaultResourceValue(self):
return self
security.declareProtected(Permissions.AccessContentsInformation,
'searchTransformationList')
def searchTransformationList(self, context, **kw):
"""
Find all transformations matching given context
"""
portal = self.getPortalObject()
return portal.portal_domains.searchPredicateList(context,
portal_type=portal.getPortalTransformationTypeList(),
**kw)
security.declareProtected(Permissions.AccessContentsInformation,
'getDefaultTransformationValue')
def getDefaultTransformationValue(self, context=None):
def getDefaultTransformationValue(self, context=None, **kw):
"""
If context is None, returns the first available transformation that
use self as a Resource. If there are several candidates, return the
......@@ -302,9 +312,7 @@ class Resource(XMLObject, XMLMatrix, VariatedMixin):
if method is not None:
return method(context)
transformation_list = self.portal_domains.searchPredicateList(context,
portal_type=self.getPortalObject().getPortalTransformationTypeList(),
limit=1)
transformation_list = self.searchTransformationList(context, **kw)
if len(transformation_list) > 0:
return transformation_list[0]
......
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