Commit bffa30cb authored by Jérome Perrin's avatar Jérome Perrin

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
parent 4ffc44a8
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
############################################################################## ##############################################################################
from AccessControl import ClassSecurityInfo, getSecurityManager from AccessControl import ClassSecurityInfo, getSecurityManager
from MethodObject import Method
from Globals import InitializeClass, DTMLFile from Globals import InitializeClass, DTMLFile
from zLOG import LOG, INFO, PROBLEM from zLOG import LOG, INFO, PROBLEM
...@@ -40,7 +41,6 @@ from Products.ERP5Form.Document.Preference import Preference ...@@ -40,7 +41,6 @@ from Products.ERP5Form.Document.Preference import Preference
from Products.ERP5Form import _dtmldir from Products.ERP5Form import _dtmldir
from Products.ERP5Form.Document.Preference import Priority from Products.ERP5Form.Document.Preference import Priority
from MethodObject import Method
class func_code: pass class func_code: pass
...@@ -89,6 +89,7 @@ class PreferenceMethod(Method) : ...@@ -89,6 +89,7 @@ class PreferenceMethod(Method) :
self._preference_name = attribute self._preference_name = attribute
def __call__(self, instance, *args, **kw) : def __call__(self, instance, *args, **kw) :
# FIXME: Preference method doesn't support default parameter
def _getPreference(user_name="") : def _getPreference(user_name="") :
found = 0 found = 0
MARKER = [] MARKER = []
...@@ -133,27 +134,10 @@ class PreferenceTool(BaseTool): ...@@ -133,27 +134,10 @@ class PreferenceTool(BaseTool):
BaseTool.inheritedAttribute('manage_afterAdd')(self, item, container) BaseTool.inheritedAttribute('manage_afterAdd')(self, item, container)
security.declareProtected(Permissions.View, "getPreference") 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. """ """ get the preference on the most appopriate Preference object. """
LOG("PreferenceTool", PROBLEM, 'calling getPreference directly on the '+ return getattr(self, 'get%s' %
'tool is deprecated, no caching happens !') convertToUpperCase(pref_name))(default=default)
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)
security.declareProtected(Permissions.ModifyPortalContent, "setPreference") security.declareProtected(Permissions.ModifyPortalContent, "setPreference")
def setPreference(self, pref_name, value) : def setPreference(self, pref_name, value) :
......
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