From bffa30cbe6895c644333750b03bcb0f34b4db908 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Tue, 23 May 2006 20:11:01 +0000
Subject: [PATCH] remove old getPreference implementation to call preference
 method accessor (whose results are cached)

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@7466 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5Form/PreferenceTool.py | 26 +++++---------------------
 1 file changed, 5 insertions(+), 21 deletions(-)

diff --git a/product/ERP5Form/PreferenceTool.py b/product/ERP5Form/PreferenceTool.py
index dbd7b778c1..9b19df0a79 100644
--- a/product/ERP5Form/PreferenceTool.py
+++ b/product/ERP5Form/PreferenceTool.py
@@ -27,6 +27,7 @@
 ##############################################################################
 
 from AccessControl import ClassSecurityInfo, getSecurityManager
+from MethodObject import Method
 from Globals import InitializeClass, DTMLFile
 from zLOG import LOG, INFO, PROBLEM
 
@@ -40,7 +41,6 @@ from Products.ERP5Form.Document.Preference import Preference
 from Products.ERP5Form import _dtmldir
 from Products.ERP5Form.Document.Preference import Priority
 
-from MethodObject import Method
 
 class func_code: pass
 
@@ -89,6 +89,7 @@ class PreferenceMethod(Method) :
     self._preference_name = attribute
 
   def __call__(self, instance, *args, **kw) :
+    # FIXME: Preference method doesn't support default parameter
     def _getPreference(user_name="") :
       found = 0
       MARKER = []
@@ -133,27 +134,10 @@ class PreferenceTool(BaseTool):
     BaseTool.inheritedAttribute('manage_afterAdd')(self, item, container)
 
   security.declareProtected(Permissions.View, "getPreference")
-  def getPreference(self, pref_name) :
+  def getPreference(self, pref_name, default=None) :
     """ get the preference on the most appopriate Preference object. """
-    LOG("PreferenceTool", PROBLEM, 'calling getPreference directly on the '+
-                                   'tool is deprecated, no caching happens !')
-    def _getPreference(pref_name="") :
-      found = 0
-      MARKER = []
-      for pref in self._getSortedPreferenceList() :
-        attr = getattr(pref, pref_name, MARKER)
-        if attr is not MARKER :
-          found = 1
-          # test the attr is set
-          if callable(attr) :
-            value = attr()
-          else :
-            value = attr
-          if value not in (None, '', (), []) :
-            return attr
-      if found :
-        return value
-    return _getPreference(pref_name=pref_name)
+    return getattr(self, 'get%s' %
+        convertToUpperCase(pref_name))(default=default)
 
   security.declareProtected(Permissions.ModifyPortalContent, "setPreference")
   def setPreference(self, pref_name, value) :
-- 
2.30.9