[Checkins] SVN: Products.CMFCore/trunk/Products/CMFCore/ - added support for add view actions

Yvo Schubbe y.2008 at wcm-solutions.de
Tue Jul 29 14:31:30 EDT 2008


Log message for revision 88976:
  - added support for add view actions

Changed:
  U   Products.CMFCore/trunk/Products/CMFCore/ActionInformation.py
  U   Products.CMFCore/trunk/Products/CMFCore/CHANGES.txt
  U   Products.CMFCore/trunk/Products/CMFCore/TypesTool.py
  U   Products.CMFCore/trunk/Products/CMFCore/exportimport/tests/test_typeinfo.py
  U   Products.CMFCore/trunk/Products/CMFCore/tests/test_TypesTool.py

-=-
Modified: Products.CMFCore/trunk/Products/CMFCore/ActionInformation.py
===================================================================
--- Products.CMFCore/trunk/Products/CMFCore/ActionInformation.py	2008-07-29 18:14:28 UTC (rev 88975)
+++ Products.CMFCore/trunk/Products/CMFCore/ActionInformation.py	2008-07-29 18:31:26 UTC (rev 88976)
@@ -181,7 +181,7 @@
             (lazy_map, lazy_keys) = action.getInfoData()
             UserDict.__init__(self, lazy_map)
 
-        self.data['allowed'] = True
+        self.data.setdefault('allowed', True)
         permissions = self.data.pop( 'permissions', () )
         if permissions:
             self.data['allowed'] = self._checkPermissions

Modified: Products.CMFCore/trunk/Products/CMFCore/CHANGES.txt
===================================================================
--- Products.CMFCore/trunk/Products/CMFCore/CHANGES.txt	2008-07-29 18:14:28 UTC (rev 88975)
+++ Products.CMFCore/trunk/Products/CMFCore/CHANGES.txt	2008-07-29 18:31:26 UTC (rev 88976)
@@ -2,6 +2,11 @@
 
   Products.CMFCore 2.2.0 (unreleased)
 
+    - TypeInformation and TypesTool: Added support for add view actions.
+      Type infos now have a new 'add_view_expr' property and implement IAction.
+      'listActions' of the types tool includes type infos as 'add' actions if
+      an add view URL is specified.
+
     - interfaces: Fixed some docstrings.
       There is no IActionInformation. ActionInformation is an old action class
       that implements IAction, non-persistent IActionInfo objects adapt action

Modified: Products.CMFCore/trunk/Products/CMFCore/TypesTool.py
===================================================================
--- Products.CMFCore/trunk/Products/CMFCore/TypesTool.py	2008-07-29 18:14:28 UTC (rev 88975)
+++ Products.CMFCore/trunk/Products/CMFCore/TypesTool.py	2008-07-29 18:31:26 UTC (rev 88976)
@@ -42,6 +42,8 @@
 from exceptions import AccessControl_Unauthorized
 from exceptions import BadRequest
 from exceptions import zExceptions_Unauthorized
+from Expression import Expression
+from interfaces import IAction
 from interfaces import ITypeInformation
 from interfaces import ITypesTool
 from permissions import AccessContentsInformation
@@ -63,6 +65,8 @@
     """ Base class for information about a content type.
     """
 
+    implements(IAction)
+
     manage_options = ( SimpleItemWithProperties.manage_options[:1]
                      + ( {'label':'Aliases',
                           'action':'manage_aliases'}, )
@@ -90,6 +94,8 @@
         )
 
     _advanced_properties = (
+        {'id': 'add_view_expr', 'type': 'string', 'mode': 'w',
+         'label': 'Add view URL (Expression)'},
         {'id':'immediate_view', 'type': 'string', 'mode':'w',
          'label':'Initial view name'},
         {'id':'global_allow', 'type': 'boolean', 'mode':'w',
@@ -112,6 +118,7 @@
     i18n_domain = ''
     content_meta_type = ''
     content_icon = ''
+    add_view_expr = ''
     immediate_view = ''
     filter_content_types = True
     allowed_content_types = ()
@@ -314,6 +321,55 @@
             method_id = method_id[0]
         return method_id
 
+    #
+    #   'IAction' interface methods
+    #
+    security.declarePrivate('getInfoData')
+    def getInfoData(self):
+        """ Get the data needed to create an ActionInfo.
+        """
+        lazy_keys = ['available', 'allowed']
+        lazy_map = {}
+
+        lazy_map['id'] = self.getId()
+        lazy_map['category'] = 'folder/add'
+        lazy_map['title'] = self.Title()
+        lazy_map['description'] = self.Description()
+        if self.add_view_expr:
+            lazy_map['url'] = self.add_view_expr_object
+            lazy_keys.append('url')
+        else:
+            lazy_map['url'] = ''
+        if self.content_icon:
+            lazy_map['icon'] = Expression('string:${portal_url}/%s'
+                                          % self.content_icon)
+            lazy_keys.append('icon')
+        else:
+            lazy_map['icon'] = ''
+        lazy_map['visible'] = True
+        lazy_map['available'] = self._checkAvailable
+        lazy_map['allowed'] = self._checkAllowed
+
+        return (lazy_map, lazy_keys)
+
+    def _setPropValue(self, id, value):
+        self._wrapperCheck(value)
+        if isinstance(value, list):
+            value = tuple(value)
+        setattr(self, id, value)
+        if value and id.endswith('_expr'):
+            setattr(self, '%s_object' % id, Expression(value))
+
+    def _checkAvailable(self, ec):
+        """ Check if the action is available in the current context.
+        """
+        return ec.contexts['folder'].getTypeInfo().allowType(self.getId())
+
+    def _checkAllowed(self, ec):
+        """ Check if the action is allowed in the current context.
+        """
+        return self.isConstructionAllowed(ec.contexts['folder'])
+
 InitializeClass(TypeInformation)
 
 
@@ -728,6 +784,10 @@
             if type_info is not None:
                 actions.extend( type_info.listActions(info, object) )
 
+        add_actions = [ ti for ti in self.objectValues()
+                        if IAction.providedBy(ti) and ti.add_view_expr ]
+        actions.extend(add_actions)
+
         return actions
 
     security.declareProtected(ManagePortal, 'listMethodAliasKeys')

Modified: Products.CMFCore/trunk/Products/CMFCore/exportimport/tests/test_typeinfo.py
===================================================================
--- Products.CMFCore/trunk/Products/CMFCore/exportimport/tests/test_typeinfo.py	2008-07-29 18:14:28 UTC (rev 88975)
+++ Products.CMFCore/trunk/Products/CMFCore/exportimport/tests/test_typeinfo.py	2008-07-29 18:31:26 UTC (rev 88976)
@@ -43,6 +43,7 @@
  <property name="content_meta_type"></property>
  <property name="product"></property>
  <property name="factory"></property>
+ <property name="add_view_expr"></property>
  <property name="immediate_view"></property>
  <property name="global_allow">True</property>
  <property name="filter_content_types">True</property>
@@ -73,6 +74,7 @@
     'content_icon':          'foo.png',
     'product':               'CMFSetup',
     'factory':               'addFoo',
+    'add_view_expr':         'string:${folder_url}/foo_add_view',
     'immediate_view':        'foo_view',
     'filter_content_types':  False,
     'allowed_content_types': (),
@@ -105,6 +107,7 @@
     'content_icon':          'bar.png',
     'constructor_path':      'make_bar',
     'permission':            'Add portal content',
+    'add_view_expr':         'string:${folder_url}/bar_add_view',
     'immediate_view':        'bar_view',
     'filter_content_types':  True,
     'allowed_content_types': ('foo',),
@@ -185,6 +188,7 @@
  <property name="content_meta_type">Foo Thing</property>
  <property name="product">CMFSetup</property>
  <property name="factory">addFoo</property>
+ <property name="add_view_expr">string:${folder_url}/foo_add_view</property>
  <property name="immediate_view">foo_view</property>
  <property name="global_allow">False</property>
  <property name="filter_content_types">False</property>
@@ -218,6 +222,7 @@
  <property name="content_meta_type">Bar Thing</property>
  <property name="permission">Add portal content</property>
  <property name="constructor_path">make_bar</property>
+ <property name="add_view_expr">string:${folder_url}/bar_add_view</property>
  <property name="immediate_view">bar_view</property>
  <property name="global_allow">True</property>
  <property name="filter_content_types">True</property>

Modified: Products.CMFCore/trunk/Products/CMFCore/tests/test_TypesTool.py
===================================================================
--- Products.CMFCore/trunk/Products/CMFCore/tests/test_TypesTool.py	2008-07-29 18:14:28 UTC (rev 88975)
+++ Products.CMFCore/trunk/Products/CMFCore/tests/test_TypesTool.py	2008-07-29 18:31:26 UTC (rev 88976)
@@ -277,6 +277,57 @@
         ti.setMethodAliases( ti.getMethodAliases() )
         self.assertEqual( ti.getMethodAliases(), FTIDATA_CMF15[0]['aliases'] )
 
+    def test_getInfoData(self):
+        ti_data = {'id': 'foo',
+                   'title': 'Foo',
+                   'description': 'Foo objects are just used for testing.',
+                   'content_icon': 'foo_icon.gif',
+                   'content_meta_type': 'Foo Content',
+                   'factory' : 'cmf.foo',
+                   'add_view_expr': 'string:${folder_url}/foo_add_view'}
+        ti = self._makeInstance(**ti_data)
+        info_data = ti.getInfoData()
+        self.assertEqual(len(info_data), 2)
+
+        self.assertEqual(len(info_data[0]), 9)
+        self.assertEqual(info_data[0]['id'], ti_data['id'])
+        self.assertEqual(info_data[0]['category'], 'folder/add')
+        self.assertEqual(info_data[0]['title'], ti_data['title'])
+        self.assertEqual(info_data[0]['description'], ti_data['description'])
+        self.assertEqual(info_data[0]['url'].text,
+                         'string:${folder_url}/foo_add_view')
+        self.assertEqual(info_data[0]['icon'].text,
+                         'string:${portal_url}/foo_icon.gif')
+        self.assertEqual(info_data[0]['visible'], True)
+        self.assertEqual(info_data[0]['available'], ti._checkAvailable)
+        self.assertEqual(info_data[0]['allowed'], ti._checkAllowed)
+
+        self.assertEqual(set(info_data[1]),
+                         set(['url', 'icon', 'available', 'allowed']))
+
+    def test_getInfoData_without_urls(self):
+        ti_data = {'id': 'foo',
+                   'title': 'Foo',
+                   'description': 'Foo objects are just used for testing.',
+                   'content_meta_type': 'Foo Content',
+                   'factory' : 'cmf.foo'}
+        ti = self._makeInstance(**ti_data)
+        info_data = ti.getInfoData()
+        self.assertEqual(len(info_data), 2)
+
+        self.assertEqual(len(info_data[0]), 9)
+        self.assertEqual(info_data[0]['id'], ti_data['id'])
+        self.assertEqual(info_data[0]['category'], 'folder/add')
+        self.assertEqual(info_data[0]['title'], ti_data['title'])
+        self.assertEqual(info_data[0]['description'], ti_data['description'])
+        self.assertEqual(info_data[0]['url'], '')
+        self.assertEqual(info_data[0]['icon'], '')
+        self.assertEqual(info_data[0]['visible'], True)
+        self.assertEqual(info_data[0]['available'], ti._checkAvailable)
+        self.assertEqual(info_data[0]['allowed'], ti._checkAllowed)
+
+        self.assertEqual(set(info_data[1]), set(['available', 'allowed']))
+
     def _checkContentTI(self, ti):
         wanted_aliases = { 'view': 'dummy_view', '(Default)': 'dummy_view' }
         wanted_actions_text0 = 'string:${object_url}/dummy_view'



More information about the Checkins mailing list