[Checkins] SVN: Products.CMFCore/branches/2.2/Products/CMFCore/ Actions and TypeInformation: Clear the compiled *_expr_object property
Ross Patterson
me at rpatterson.net
Mon Apr 5 21:13:49 EDT 2010
Log message for revision 110533:
Actions and TypeInformation: Clear the compiled *_expr_object property
when the *_expr property is cleared.
Changed:
U Products.CMFCore/branches/2.2/Products/CMFCore/ActionInformation.py
U Products.CMFCore/branches/2.2/Products/CMFCore/CHANGES.txt
U Products.CMFCore/branches/2.2/Products/CMFCore/TypesTool.py
U Products.CMFCore/branches/2.2/Products/CMFCore/tests/test_ActionInformation.py
U Products.CMFCore/branches/2.2/Products/CMFCore/tests/test_TypesTool.py
-=-
Modified: Products.CMFCore/branches/2.2/Products/CMFCore/ActionInformation.py
===================================================================
--- Products.CMFCore/branches/2.2/Products/CMFCore/ActionInformation.py 2010-04-05 20:31:44 UTC (rev 110532)
+++ Products.CMFCore/branches/2.2/Products/CMFCore/ActionInformation.py 2010-04-06 01:13:49 UTC (rev 110533)
@@ -120,8 +120,12 @@
if isinstance(value, list):
value = tuple(value)
setattr(self, id, value)
- if value and id.endswith('_expr'):
- setattr( self, '%s_object' % id, Expression(value) )
+ if id.endswith('_expr'):
+ attr = '%s_object' % id
+ if value:
+ setattr(self, attr, Expression(value))
+ elif hasattr(self, attr):
+ delattr(self, attr)
security.declarePrivate('getInfoData')
def getInfoData(self):
Modified: Products.CMFCore/branches/2.2/Products/CMFCore/CHANGES.txt
===================================================================
--- Products.CMFCore/branches/2.2/Products/CMFCore/CHANGES.txt 2010-04-05 20:31:44 UTC (rev 110532)
+++ Products.CMFCore/branches/2.2/Products/CMFCore/CHANGES.txt 2010-04-06 01:13:49 UTC (rev 110533)
@@ -4,6 +4,9 @@
2.2.1-beta (unreleased)
-----------------------
+- Actions and TypeInformation: Clear the compiled *_expr_object
+ property when the *_expr property is cleared.
+
- Actions: Return None if 'link_target' is an empty string.
This helps to avoid invalid empty 'target' attributes in HTML output.
Modified: Products.CMFCore/branches/2.2/Products/CMFCore/TypesTool.py
===================================================================
--- Products.CMFCore/branches/2.2/Products/CMFCore/TypesTool.py 2010-04-05 20:31:44 UTC (rev 110532)
+++ Products.CMFCore/branches/2.2/Products/CMFCore/TypesTool.py 2010-04-06 01:13:49 UTC (rev 110533)
@@ -408,8 +408,12 @@
if isinstance(value, list):
value = tuple(value)
setattr(self, id, value)
- if value and id.endswith('_expr'):
- setattr(self, '%s_object' % id, Expression(value))
+ if id.endswith('_expr'):
+ attr = '%s_object' % id
+ if value:
+ setattr(self, attr, Expression(value))
+ elif hasattr(self, attr):
+ delattr(self, attr)
def _checkAvailable(self, ec):
""" Check if the action is available in the current context.
Modified: Products.CMFCore/branches/2.2/Products/CMFCore/tests/test_ActionInformation.py
===================================================================
--- Products.CMFCore/branches/2.2/Products/CMFCore/tests/test_ActionInformation.py 2010-04-05 20:31:44 UTC (rev 110532)
+++ Products.CMFCore/branches/2.2/Products/CMFCore/tests/test_ActionInformation.py 2010-04-06 01:13:49 UTC (rev 110533)
@@ -118,6 +118,29 @@
self.failUnless('value=" Add "' in form_html)
+ def test_clearExprObjects(self):
+ """When a *_expr property is set, a *_expr_object attribute is
+ also set which should also be cleared when the *_expr is
+ cleared."""
+ a = self._makeOne('foo',
+ title='Foo Title',
+ description='Foo description.',
+ url_expr='string:${object_url}/foo_url',
+ icon_expr='string:foo_icon',
+ available_expr='',
+ permissions=('View',),
+ visible=False,
+ link_target='_top')
+ self.failUnless(hasattr(a, 'icon_expr_object'))
+ self.failUnless(hasattr(a, 'url_expr_object'))
+ self.failIf(hasattr(a, 'available_expr_object'))
+ a.manage_changeProperties(
+ icon_expr='', url_expr='', available_expr='')
+ self.failIf(hasattr(a, 'icon_expr_object'))
+ self.failIf(hasattr(a, 'url_expr_object'))
+ self.failIf(hasattr(a, 'available_expr_object'))
+
+
class DummyRequest:
def __init__(self):
self._data = {}
Modified: Products.CMFCore/branches/2.2/Products/CMFCore/tests/test_TypesTool.py
===================================================================
--- Products.CMFCore/branches/2.2/Products/CMFCore/tests/test_TypesTool.py 2010-04-05 20:31:44 UTC (rev 110532)
+++ Products.CMFCore/branches/2.2/Products/CMFCore/tests/test_TypesTool.py 2010-04-06 01:13:49 UTC (rev 110533)
@@ -471,7 +471,36 @@
self.assertEqual(ti._actions[1].action.text, wanted_actions_text1)
self.assertEqual(ti._actions[2].action.text, wanted_actions_text2)
+ def test_clearExprObjects(self):
+ """When a *_expr property is set, a *_expr_object attribute is
+ also set which should also be cleared when the *_expr is
+ cleared."""
+ ti_data = {'id': 'foo',
+ 'title': 'Foo',
+ 'description': 'Foo objects are just used for testing.',
+ 'content_meta_type': 'Foo Content',
+ 'factory': 'cmf.foo',
+ 'icon_expr': 'string:${portal_url}/foo_icon_expr.gif',
+ 'add_view_expr': 'string:${folder_url}/foo_add_view',
+ 'link_target': '_new'}
+ ti = self._makeOne(**ti_data)
+ info_data = ti.getInfoData()
+ self.failUnless(hasattr(ti, 'icon_expr_object'))
+ self.failUnless(info_data[0].get('icon'))
+ self.failUnless('icon' in info_data[1])
+ self.failUnless(hasattr(ti, 'add_view_expr_object'))
+ self.failUnless(info_data[0].get('url'))
+ self.failUnless('url' in info_data[1])
+ ti.manage_changeProperties(icon_expr='', add_view_expr='')
+ info_data = ti.getInfoData()
+ self.failIf(hasattr(ti, 'icon_expr_object'))
+ self.failIf(info_data[0].get('icon'))
+ self.failIf('icon' in info_data[1])
+ self.failIf(hasattr(ti, 'add_view_expr_object'))
+ self.failIf(info_data[0].get('url'))
+ self.failIf('url' in info_data[1])
+
class FTIDataTests( TypeInfoTests, unittest.TestCase ):
def _getTargetClass(self):
More information about the checkins
mailing list