From 7af9e70b92714faa0111c804515d5c33200e48c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com> Date: Thu, 16 Aug 2007 09:12:20 +0000 Subject: [PATCH] PreferenceTool.getPreference method now accepts a default parameter, for consistency with other getters. git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@15695 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ERP5Form/PreferenceTool.py | 6 ++++-- product/ERP5Form/tests/testPreferences.py | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/product/ERP5Form/PreferenceTool.py b/product/ERP5Form/PreferenceTool.py index ded1553db8..8aa843da41 100644 --- a/product/ERP5Form/PreferenceTool.py +++ b/product/ERP5Form/PreferenceTool.py @@ -175,8 +175,10 @@ class PreferenceTool(BaseTool): security.declareProtected(Permissions.View, "getPreference") def getPreference(self, pref_name, default=None) : """ get the preference on the most appopriate Preference object. """ - return getattr(self, 'get%s' % - convertToUpperCase(pref_name))(default=default) + method = getattr(self, 'get%s' % convertToUpperCase(pref_name), None) + if method: + return method(default=default) + return default security.declareProtected(Permissions.ModifyPortalContent, "setPreference") def setPreference(self, pref_name, value) : diff --git a/product/ERP5Form/tests/testPreferences.py b/product/ERP5Form/tests/testPreferences.py index c45128432f..277209bd45 100644 --- a/product/ERP5Form/tests/testPreferences.py +++ b/product/ERP5Form/tests/testPreferences.py @@ -206,6 +206,10 @@ class TestPreferences(ERP5TypeTestCase): 'preferred_accounting_transaction_simulation_state_list')), list(group.getPreferredAccountingTransactionSimulationStateList())) + self.assertEquals('default', pref_tool.getPreference( + 'this_does_not_exists', 'default')) + + def test_GetAttr(self, quiet=quiet, run=run_all_tests) : """ checks that preference methods can be called directly on portal_preferences """ -- 2.30.9