Commit 0f78c0f3 authored by Sebastien Robin's avatar Sebastien Robin

store the result of _getSortedPreferenceList in a transactional

variable

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@38131 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 19c8a446
...@@ -41,6 +41,7 @@ from Products.ERP5Type import Permissions, PropertySheet ...@@ -41,6 +41,7 @@ from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5Type.Cache import CachingMethod from Products.ERP5Type.Cache import CachingMethod
from Products.ERP5Type.Utils import convertToUpperCase from Products.ERP5Type.Utils import convertToUpperCase
from Products.ERP5Type.Accessor.TypeDefinition import list_types from Products.ERP5Type.Accessor.TypeDefinition import list_types
from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
from Products.ERP5Form import _dtmldir from Products.ERP5Form import _dtmldir
_marker = object() _marker = object()
...@@ -225,29 +226,37 @@ class PreferenceTool(BaseTool): ...@@ -225,29 +226,37 @@ class PreferenceTool(BaseTool):
""" 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
""" """
prefs = [] tv = getTransactionalVariable(self)
# XXX will also cause problems with Manager (too long) tv_key = 'PreferenceTool._getSortedPreferenceList/%s' % sql_catalog_id
# XXX For manager, create a manager specific preference if tv.get(tv_key, None) is None:
# or better solution prefs = []
user = getToolByName(self, 'portal_membership').getAuthenticatedMember() # XXX will also cause problems with Manager (too long)
user_is_manager = 'Manager' in user.getRolesInContext(self) # XXX For manager, create a manager specific preference
for pref in self.searchFolder(portal_type='Preference', sql_catalog_id=sql_catalog_id): # or better solution
pref = pref.getObject() user = getToolByName(self, 'portal_membership').getAuthenticatedMember()
if pref is not None and pref.getProperty('preference_state', user_is_manager = 'Manager' in user.getRolesInContext(self)
'broken') in ('enabled', 'global'): for pref in self.searchFolder(portal_type='Preference', sql_catalog_id=sql_catalog_id):
# XXX quick workaround so that manager only see user preference pref = pref.getObject()
# they actually own. if pref is not None and pref.getProperty('preference_state',
if user_is_manager and pref.getPriority() == Priority.USER : 'broken') in ('enabled', 'global'):
if pref.getOwnerTuple()[1] == user.getId(): # XXX quick workaround so that manager only see user preference
# they actually own.
if user_is_manager and pref.getPriority() == Priority.USER :
if pref.getOwnerTuple()[1] == user.getId():
prefs.append(pref)
else :
prefs.append(pref) prefs.append(pref)
else : prefs.sort(key=lambda x: x.getPriority(), reverse=True)
prefs.append(pref) # add system preferences before user preferences
prefs.sort(key=lambda x: x.getPriority(), reverse=True) sys_prefs = [x.getObject() for x in self.searchFolder(portal_type='System Preference', sql_catalog_id=sql_catalog_id) \
# add system preferences before user preferences if x.getObject().getProperty('preference_state', 'broken') in ('enabled', 'global')]
sys_prefs = [x.getObject() for x in self.searchFolder(portal_type='System Preference', sql_catalog_id=sql_catalog_id) \ sys_prefs.sort(key=lambda x: x.getPriority(), reverse=True)
if x.getObject().getProperty('preference_state', 'broken') in ('enabled', 'global')] preference_list = sys_prefs + prefs
sys_prefs.sort(key=lambda x: x.getPriority(), reverse=True) tv[tv_key] = [x.getRelativeUrl() for x in preference_list]
return sys_prefs + prefs else:
portal = self.getPortalObject()
preference_list = [portal.restrictedTraverse(x) for x in tv[tv_key]]
return preference_list
def _getActivePreferenceByPortalType(self, portal_type): def _getActivePreferenceByPortalType(self, portal_type):
enabled_prefs = self._getSortedPreferenceList() enabled_prefs = self._getSortedPreferenceList()
......
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