Commit 930ea683 authored by Jérome Perrin's avatar Jérome Perrin

generate "is" accessors for boolean preferences


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@34637 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent a8b6659b
...@@ -93,8 +93,10 @@ def createPreferenceToolAccessorList(portal) : ...@@ -93,8 +93,10 @@ def createPreferenceToolAccessorList(portal) :
# only properties marked as preference are used # only properties marked as preference are used
attribute = prop['id'] attribute = prop['id']
attr_list = [ 'get%s' % convertToUpperCase(attribute)] attr_list = [ 'get%s' % convertToUpperCase(attribute)]
if prop['type'] == 'boolean':
attr_list.append('is%s' % convertToUpperCase(attribute))
if prop['type'] in list_types : if prop['type'] in list_types :
attr_list += ['get%sList' % convertToUpperCase(attribute), ] attr_list.append('get%sList' % convertToUpperCase(attribute))
for attribute_name in attr_list: for attribute_name in attr_list:
method = PreferenceMethod(attribute_name, prop.get('default')) method = PreferenceMethod(attribute_name, prop.get('default'))
setattr(PreferenceTool, attribute_name, method) setattr(PreferenceTool, attribute_name, method)
......
...@@ -509,6 +509,26 @@ class TestPreferences(ERP5TypeTestCase): ...@@ -509,6 +509,26 @@ class TestPreferences(ERP5TypeTestCase):
self.assertEqual(user_pref, preference_tool.getActivePreference()) self.assertEqual(user_pref, preference_tool.getActivePreference())
self.assertEqual(system_pref, preference_tool.getActiveSystemPreference()) self.assertEqual(system_pref, preference_tool.getActiveSystemPreference())
def test_boolean_accessor(self):
self._addPropertySheet('Preference', 'DummyPreference',
'''class DummyPreference:
_properties= ( {'id': 'dummy',
'preference': True,
'type': 'boolean',},)''')
portal_preferences = self.portal.portal_preferences
self.assertFalse(portal_preferences.getDummy())
self.assertFalse(portal_preferences.isDummy())
preference = portal_preferences.newContent(portal_type='Preference',
dummy=True)
preference.enable()
transaction.commit()
self.tic()
self.assertTrue(portal_preferences.getDummy())
self.assertTrue(portal_preferences.isDummy())
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestPreferences)) suite.addTest(unittest.makeSuite(TestPreferences))
......
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