Commit 5af48b05 authored by Łukasz Nowak's avatar Łukasz Nowak

- add private method to return preference by portal type

 - add getActiveSystemPreference to fetch only System Preference
 - update getActivePreference to return only Preference
 - update test to check for getActiveSystemPreference and getActivePreference behaviour


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@28291 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent bc4247e4
......@@ -239,13 +239,27 @@ class PreferenceTool(BaseTool):
sys_prefs.sort(key=lambda x: x.getPriority(), reverse=True)
return sys_prefs + prefs
def _getActivePreferenceByPortalType(self, portal_type):
enabled_prefs = self._getSortedPreferenceList()
if len(enabled_prefs) > 0 :
try:
return [x for x in enabled_prefs
if x.getPortalType() == portal_type][0]
except IndexError:
pass
return None
security.declareProtected(Permissions.View, 'getActivePreference')
def getActivePreference(self) :
""" returns the current preference for the user.
Note that this preference may be read only. """
enabled_prefs = self._getSortedPreferenceList()
if len(enabled_prefs) > 0 :
return enabled_prefs[0]
return self._getActivePreferenceByPortalType('Preference')
security.declareProtected(Permissions.View, 'getActiveSystemPreference')
def getActiveSystemPreference(self) :
""" returns the current system preference for the user.
Note that this preference may be read only. """
return self._getActivePreferenceByPortalType('System Preference')
security.declareProtected(Permissions.View, 'getDocumentTemplateList')
def getDocumentTemplateList(self, folder=None) :
......
......@@ -470,6 +470,7 @@ class TestPreferences(ERP5TypeTestCase):
# even if there is System Preference enabled getActivePreference shall return
# user preference
self.assertEqual(user_pref, preference_tool.getActivePreference())
self.assertEqual(site_pref, preference_tool.getActiveSystemPreference())
def test_suite():
suite = unittest.TestSuite()
......
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