Commit 968722fa authored by Vincent Pelletier's avatar Vincent Pelletier

It is obviously invalid to pass args and kw to *both* underlying preference...

It is obviously invalid to pass args and kw to *both* underlying preference accessor and searchFolder (via _getSortedPreferenceList). Fix that by passing them through to underlying preference accessor, since those args & kw come from an accessor-like method, so their API is consistent.
To preserve backward compatibility, accept passing through sql_catalog_id, but add an XXX comment about that and what uses it.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@26550 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 51720733
...@@ -126,7 +126,11 @@ class PreferenceMethod(Method): ...@@ -126,7 +126,11 @@ class PreferenceMethod(Method):
def __call__(self, instance, *args, **kw): def __call__(self, instance, *args, **kw):
def _getPreference(*args, **kw): def _getPreference(*args, **kw):
value = None value = None
for pref in instance._getSortedPreferenceList(*args, **kw): # XXX: sql_catalog_id is passed when calling getPreferredArchive
# This is inconsistent with regular accessor API, and indicates that
# there is a design problem in current archive API.
sql_catalog_id = kw.pop('sql_catalog_id', None)
for pref in instance._getSortedPreferenceList(sql_catalog_id=sql_catalog_id):
value = getattr(pref, self._preference_name, _marker) value = getattr(pref, self._preference_name, _marker)
# XXX-JPS Why don't we use accessors here such as: # XXX-JPS Why don't we use accessors here such as:
# value = pref.getProperty(self._preference_name, _marker) # value = pref.getProperty(self._preference_name, _marker)
...@@ -207,7 +211,7 @@ class PreferenceTool(BaseTool): ...@@ -207,7 +211,7 @@ class PreferenceTool(BaseTool):
""" set the preference on the active Preference object""" """ set the preference on the active Preference object"""
self.getActivePreference()._edit(**{pref_name:value}) self.getActivePreference()._edit(**{pref_name:value})
def _getSortedPreferenceList(self, *args, **kw) : def _getSortedPreferenceList(self, sql_catalog_id=None):
""" return the most appropriate preferences objects, """ return the most appropriate preferences objects,
sorted so that the first in the list should be applied first sorted so that the first in the list should be applied first
""" """
...@@ -217,7 +221,7 @@ class PreferenceTool(BaseTool): ...@@ -217,7 +221,7 @@ class PreferenceTool(BaseTool):
# or better solution # or better solution
user = getToolByName(self, 'portal_membership').getAuthenticatedMember() user = getToolByName(self, 'portal_membership').getAuthenticatedMember()
user_is_manager = 'Manager' in user.getRolesInContext(self) user_is_manager = 'Manager' in user.getRolesInContext(self)
for pref in self.searchFolder(portal_type='Preference', **kw) : for pref in self.searchFolder(portal_type='Preference', sql_catalog_id=sql_catalog_id):
pref = pref.getObject() pref = pref.getObject()
if pref is not None and pref.getProperty('preference_state', if pref is not None and pref.getProperty('preference_state',
'broken') in ('enabled', 'global'): 'broken') in ('enabled', 'global'):
...@@ -230,7 +234,7 @@ class PreferenceTool(BaseTool): ...@@ -230,7 +234,7 @@ class PreferenceTool(BaseTool):
prefs.append(pref) prefs.append(pref)
prefs.sort(key=lambda x: x.getPriority(), reverse=True) prefs.sort(key=lambda x: x.getPriority(), reverse=True)
# add system preferences after user preferences # add system preferences after user preferences
sys_prefs = [x.getObject() for x in self.searchFolder(portal_type='System Preference', **kw) \ sys_prefs = [x.getObject() for x in self.searchFolder(portal_type='System Preference', sql_catalog_id=sql_catalog_id) \
if x.getObject().getProperty('preference_state', 'broken') in ('enabled', 'global')] if x.getObject().getProperty('preference_state', 'broken') in ('enabled', 'global')]
sys_prefs.sort(key=lambda x: x.getPriority(), reverse=True) sys_prefs.sort(key=lambda x: x.getPriority(), reverse=True)
return sys_prefs + prefs return sys_prefs + prefs
......
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