Commit 2706a178 authored by Arnaud Fontaine's avatar Arnaud Fontaine

simulation: Define getTestedProperty() on mixin rather than subclasses.

This makes more sense as all Tester inherits from EquivalenceTesterMixin,
even project-specific EquivalenceTester classes.

Also, define getTestedProperty{List,Title}() for compatibility sake as
they are still widely used.

Followup of: "simulation: improve equivalence testers explanations messages".
parent b4361eb8
......@@ -102,8 +102,3 @@ class CategoryMembershipEquivalenceTester(Predicate, EquivalenceTesterMixin):
decision_value=self.getTestedPropertyText(
decision_movement, tested_property)))
return None
# Temporary compatibility code that will fix existing data.
# This Code must be removed in 2 years (end of 2017)
from Products.ERP5.Document.StringEquivalenceTester import getTestedProperty
CategoryMembershipEquivalenceTester.getTestedProperty = getTestedProperty
......@@ -100,8 +100,3 @@ class DateTimeEquivalenceTester(Predicate, EquivalenceTesterMixin):
decision_value=decision_value,
prevision_value=prevision_value,
value=absolute_tolerance_max))
# Temporary compatibility code that will fix existing data.
# This Code must be removed in 2 years (end of 2017)
from Products.ERP5.Document.StringEquivalenceTester import getTestedProperty
DateTimeEquivalenceTester.getTestedProperty = getTestedProperty
......@@ -201,8 +201,3 @@ class FloatEquivalenceTester(Predicate, EquivalenceTesterMixin):
# converted to Decimals everywhere, then the float() call should
# go away
return float(result)
# Temporary compatibility code that will fix existing data.
# This Code must be removed in 2 years (end of 2017)
from Products.ERP5.Document.StringEquivalenceTester import getTestedProperty
FloatEquivalenceTester.getTestedProperty = getTestedProperty
......@@ -84,20 +84,3 @@ class StringEquivalenceTester(Predicate, EquivalenceTesterMixin):
decision_value=decision_value,
prevision_value=prevision_value))
return None
# Temporary compatibility code that will fix existing data.
# This Code must be removed in 2 years (end of 2017)
def getTestedProperty(self):
"""
Override getTestedProperty to fix the way it is stored. Some time
ago it was multi-valued, which is non-sense we the implementation we
have on this equivalence tester.
"""
tested_property = getattr(self, 'tested_property', None)
if tested_property != None:
if isinstance(tested_property, tuple):
if len(tested_property) == 1:
setattr(self, 'tested_property', tested_property[0])
return self._baseGetTestedProperty()
StringEquivalenceTester.getTestedProperty = getTestedProperty
......@@ -33,6 +33,7 @@ from Products.ERP5Type import Permissions, interfaces
from Products.ERP5Type.DivergenceMessage import DivergenceMessage
from Products.ERP5Type.Message import Message
from Products.PythonScripts.standard import html_quote as h
from zLOG import LOG, WARNING
class EquivalenceTesterMixin:
"""
......@@ -226,4 +227,59 @@ class EquivalenceTesterMixin:
return {tested_property: self._getTestedPropertyValue(prevision_movement,
tested_property)}
# Temporary compatibility code that will fix existing data.
# This Code must be removed in 2 years (end of 2017)
security.declareProtected(Permissions.AccessContentsInformation,
'getTestedProperty')
def getTestedProperty(self):
"""
Override getTestedProperty to fix the way it is stored. Some time
ago it was multi-valued, which is non-sense we the implementation we
have on this equivalence tester.
"""
tested_property = getattr(self, 'tested_property', None)
if (getattr(self, '_baseGetTestedPropertyList', None) is None and
isinstance(tested_property, tuple)):
if len(tested_property) == 1:
new_value = tested_property[0]
else:
new_value = None
setattr(self, 'tested_property', new_value)
LOG("equivalence_tester", WARNING,
"%s: Migrated tested_property: %r => %r" % (self.getRelativeUrl(),
tested_property,
new_value))
return self._baseGetTestedProperty()
def getTestedPropertyList(self):
if getattr(self, '_baseGetTestedPropertyList', None) is None:
return [self.getTestedProperty()]
return self._baseGetTestedPropertyList()
def getTestedPropertyTitle(self):
tested_property_title = getattr(self, 'tested_property_title', None)
if (getattr(self, '_baseGetTestedPropertyTitleList', None) is None and
isinstance(tested_property_title, tuple)):
if len(tested_property_title) == 1:
new_value = tested_property_title[0]
else:
new_value = None
setattr(self, 'tested_property_title', new_value)
LOG("equivalence_tester", WARNING,
"%s: Migrated tested_property_title: %r => %r" % (self.getRelativeUrl(),
tested_property_title,
new_value))
return self._baseGetTestedPropertyTitle()
def getTestedPropertyTitleList(self):
if getattr(self, '_baseGetTestedPropertyTitleList', None) is None:
return [self.getTestedPropertyTitle()]
return self._baseGetTestedPropertyTitleList()
InitializeClass(EquivalenceTesterMixin)
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