Commit 18118d18 authored by Jérome Perrin's avatar Jérome Perrin

Added a cache on getPreference


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@4370 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 51c2b475
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
# #
############################################################################## ##############################################################################
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo, getSecurityManager
from Globals import InitializeClass, DTMLFile from Globals import InitializeClass, DTMLFile
from Acquisition import aq_base from Acquisition import aq_base
...@@ -83,20 +83,26 @@ class PreferenceTool(BaseTool): ...@@ -83,20 +83,26 @@ class PreferenceTool(BaseTool):
security.declareProtected(Permissions.View, "getPreference") security.declareProtected(Permissions.View, "getPreference")
def getPreference(self, pref_name) : def getPreference(self, pref_name) :
""" get the preference on the most appopriate Preference object. """ """ get the preference on the most appopriate Preference object. """
found = 0 def _getPreference(self, pref_name="", user_name="") :
for pref in self._getMostAppropriatePreferences() : found = 0
attr = getattr(pref, pref_name, None) MARKER = []
if attr is not None : for pref in self._getMostAppropriatePreferences() :
found = 1 attr = getattr(pref, pref_name, MARKER)
# test the attr is set if attr is not MARKER :
if callable(attr) : found = 1
value = attr() # test the attr is set
else : if callable(attr) :
value = attr value = attr()
if value not in (None, '', (), []) : else :
return attr value = attr
if found : if value not in (None, '', (), []) :
return attr return attr
if found :
return attr
_getPreference = CachingMethod( _getPreference,
id='PreferenceTool.CachingMethod')
user_name = getSecurityManager().getUser().getId()
return _getPreference(self, pref_name=pref_name, user_name=user_name)
security.declareProtected(Permissions.ModifyPortalContent, "setPreference") security.declareProtected(Permissions.ModifyPortalContent, "setPreference")
def setPreference(self, pref_name, value) : def setPreference(self, pref_name, value) :
...@@ -144,7 +150,7 @@ class PreferenceTool(BaseTool): ...@@ -144,7 +150,7 @@ class PreferenceTool(BaseTool):
_getValidPreferenceNames, cache_duration = 600, _getValidPreferenceNames, cache_duration = 600,
id = 'PreferenceTool._getPreferenceAttributes') id = 'PreferenceTool._getPreferenceAttributes')
return _getValidPreferenceNames(self) return _getValidPreferenceNames(self)
security.declarePrivate('_getMostAppropriatePreferences') security.declarePrivate('_getMostAppropriatePreferences')
def _getMostAppropriatePreferences(self) : def _getMostAppropriatePreferences(self) :
""" return the most appropriate preferences objects, """ return the most appropriate preferences objects,
...@@ -156,7 +162,7 @@ class PreferenceTool(BaseTool): ...@@ -156,7 +162,7 @@ class PreferenceTool(BaseTool):
prefs.append(pref) prefs.append(pref)
prefs.sort(lambda b, a: cmp(a.getPriority(), b.getPriority())) prefs.sort(lambda b, a: cmp(a.getPriority(), b.getPriority()))
return prefs return prefs
security.declareProtected(Permissions.View, 'getActivePreference') security.declareProtected(Permissions.View, 'getActivePreference')
def getActivePreference(self) : def getActivePreference(self) :
""" returns the current preference for the user. """ returns the current preference for the user.
......
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