[Erp5-report] r36691 kazuhiko - /erp5/trunk/products/ERP5/Document/

nobody at svn.erp5.org nobody at svn.erp5.org
Tue Jun 29 15:10:32 CEST 2010


Author: kazuhiko
Date: Tue Jun 29 15:10:28 2010
New Revision: 36691

URL: http://svn.erp5.org?rev=36691&view=rev
Log:
cleanup and implement several APIs to get configuration values for target solvers.

Modified:
    erp5/trunk/products/ERP5/Document/SolverDecision.py
    erp5/trunk/products/ERP5/Document/SolverTypeInformation.py

Modified: erp5/trunk/products/ERP5/Document/SolverDecision.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/SolverDecision.py?rev=36691&r1=36690&r2=36691&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/SolverDecision.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Document/SolverDecision.py [utf8] Tue Jun 29 15:10:28 2010
@@ -94,23 +94,11 @@ class SolverDecision(ConfigurableMixin, 
     configurable object
     (implementation)
     """
-    # XXX To be implemented through type based method and using read
-    # transaction cache
-    try:
-      solver_portal_type = self.getSolverValue().getId()
-    except AttributeError:
+    solver_type = self.getSolverValue()
+    if solver_type is None:
       return {}
-
-    solver = self.getParentValue().newContent(
-      portal_type=solver_portal_type,
-      temp_object=True,
-      delivery_list=self.getDeliveryList(),
-      causality_value=self)
-    method = solver._getTypeBasedMethod(
-      'getDefaultConfigurationPropertyDict',
-      fallback_script_id='Solver_getDefaultConfigurationPropertyDict')
-
-    return method(self)
+    else:
+      solver_type.getDefaultConfigurationPropertyDict()
 
   def getExplanationMessage(self, all=False):
     """

Modified: erp5/trunk/products/ERP5/Document/SolverTypeInformation.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/SolverTypeInformation.py?rev=36691&r1=36690&r2=36691&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/SolverTypeInformation.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Document/SolverTypeInformation.py [utf8] Tue Jun 29 15:10:28 2010
@@ -27,7 +27,7 @@
 ##############################################################################
 
 from AccessControl import ClassSecurityInfo
-from Products.ERP5Type import Permissions, PropertySheet
+from Products.ERP5Type import Permissions, PropertySheet, interfaces
 from Products.ERP5Type.ERP5Type import ERP5TypeInformation
 from Products.ERP5.Document.Predicate import Predicate
 from Products.ERP5Type.Cache import getReadOnlyTransactionCache
@@ -151,45 +151,74 @@ class SolverTypeInformation(Predicate, E
     configurable -- a configurable document (Solver Decision
                     or Target Solver)
     """
-    # Implemented through type based method
-    # and using read transaction cache
-    if configurable.getPortalType() == 'Solver Decision':
-      try:
-        solver_portal_type = configurable.getSolverValue().getId()
-      except AttributeError:
-        return {}
-    else:
-      solver_portal_type = configurable.getPortalType()
+    return self._callTypeBasetMethod(
+      self, 'getDefaultConfigurationPropertyDict')
 
-    cache = getReadOnlyTransactionCache(self)
-    if cache is not None:
-      key = ('getDefaultConfigurationPropertyDict', solver_portal_type,
-             configurable.getRelativeUrl())
-      try:
-        method = cache[key]
-      except KeyError:
-        method = self._getTypeBasedMethod(
-          'getDefaultConfigurationPropertyDict',
-          fallback_script_id='Solver_getDefaultConfigurationPropertyDict')
-        cache[key] = method
-    return method(configurable)
-
-  def getDefaultConfigurationPropertyList(self, id, configurable):
+  def getDefaultConfigurationProperty(self, property, configurable):
     """
-    Returns a list of possible values for a given property
+    Returns the default value for a given property
     (public API)
 
     configurable -- a configurable document (Solver Decision
                     or Target Solver)
+
+    TODO: XXX-JPS unify with IConfigurable
     """
+    return self.getDefaultConfigurationPropertyDict().get(property, None)
 
-  def getDefaultConfigurationProperty(self, id, configurable):
+  def getDefaultConfigurationPropertyListDict(self, configurable):
     """
-    Returns the default value for a given property
-    (public API)
+    Returns a dictionary of possible values for specified
+    configurable object
+    (implementation)
 
     configurable -- a configurable document (Solver Decision
                     or Target Solver)
+    """
+    return self._callTypeBasetMethod(
+      self, 'getDefaultConfigurationPropertyListDict')
 
-    TODO: XXX-JPS unify with IConfigurable
+  def getDefaultConfigurationPropertyList(self, property, configurable):
     """
+    Returns a list of possible values for a given property
+    (public API)
+
+    configurable -- a configurable document (Solver Decision
+                    or Target Solver)
+    """
+    return self.getDefaultConfigurationPropertyListDict().get(property, [])
+
+  def _callTypeBasedMethod(self, method_id, configurable):
+    # Implemented through type based method
+    # and using read transaction cache
+    portal_type = configurable.getPortalType()
+    if portal_type == 'Solver Decision':
+      try:
+        solver_portal_type = self.getSolverValue().getId()
+        solver = None
+      except AttributeError:
+        return {}
+    elif interfaces.ISolver.providedBy(configurable):
+      solver_portal_type = portal_type
+      solver = configurable
+    else:
+      raise NotImplementedError, '%s is not supported for configurable argument' % portal_type
+
+    cache = getReadOnlyTransactionCache(self)
+    if cache is not None:
+      key = (method_id, solver_portal_type,
+             configurable.getRelativeUrl())
+      try:
+        method = cache[key]
+      except KeyError:
+        if solver is None:
+          solver = self.getParentValue().newContent(
+            portal_type=solver_portal_type,
+            temp_object=True,
+            delivery_list=configurable.getDeliveryList(),
+            causality_value=configurable)
+        method = solver._getTypeBasedMethod(
+          method_id,
+          fallback_script_id='Solver_%s' % method_id)
+        cache[key] = method
+    return method()




More information about the Erp5-report mailing list