[CMF-checkins] CVS: CMF/CMFSetup - actions.py:1.18

Florent Guillaume fg at nuxeo.com
Mon Feb 21 13:02:24 EST 2005


Yvo Schubbe  <zope-cmf at zope.org> wrote:
> === CMF/CMFSetup/actions.py 1.17 => 1.18 ===
> +            if p_info['actions']:
> +                for a_info in p_info['actions']:
> +                    parent = actions_tool
> +                    for category_id in a_info['category'].split('/'):
> +                        if category_id not in parent.objectIds():
> +                            o_info = {'id': str(category_id),
> +                                      'meta_type': 'CMF Action Category',
> +                                      'properties':(),
> +                                      'objects': ()}
> +                            apc.initObject(parent, o_info)
> +                        parent = parent._getOb(category_id)
> +                    if a_info['id'] not in parent.objectIds():
> +                        o_info = {'id': str(a_info['id']),
> +                                  'meta_type': 'CMF Action',
> +                                  'properties':
> +                                     ( {'id': 'title',
> +                                        'value': a_info.get('title', ''),
> +                                        'elements': ()}
> +                                     , {'id': 'description',
> +                                        'value': a_info.get('description', ''),
> +                                        'elements': ()}
> +                                     , {'id': 'url_expr',
> +                                        'value': a_info.get('action', ''),
> +                                        'elements': ()}
> +                                     , {'id': 'available_expr',
> +                                        'value': a_info.get('condition', ''),
> +                                        'elements': ()}
> +                                     , {'id': 'permissions',
> +                                        'value': '',
> +                                        'elements': a_info['permissions']}
> +                                     , {'id': 'visible',
> +                                        'value': a_info.get('visible', True),
> +                                        'elements': ()}
> +                                     ),
> +                                  'objects': ()}
> +                        apc.initObject(parent, o_info)

Nitpick: I prefer to write such code in a way that indentation is minimal:

            for a_info in p_info['actions'] or ():
                parent = actions_tool
                for category_id in a_info['category'].split('/'):
                    if category_id not in parent.objectIds():
                        o_info = {'id': str(category_id),
                                  'meta_type': 'CMF Action Category',
                                  'properties':(),
                                  'objects': ()}
                        apc.initObject(parent, o_info)
                    parent = parent._getOb(category_id)
                if a_info['id'] in parent.objectIds():
                    continue
                o_info = {'id': str(a_info['id']),
                          'meta_type': 'CMF Action',
                          'properties':
                             ( {'id': 'title',
                                'value': a_info.get('title', ''),
                                'elements': ()}
                             , {'id': 'description',
                                'value': a_info.get('description', ''),
                                'elements': ()}
                             , {'id': 'url_expr',
                                'value': a_info.get('action', ''),
                                'elements': ()}
                             , {'id': 'available_expr',
                                'value': a_info.get('condition', ''),
                                'elements': ()}
                             , {'id': 'permissions',
                                'value': '',
                                'elements': a_info['permissions']}
                             , {'id': 'visible',
                                'value': a_info.get('visible', True),
                                'elements': ()}
                             ),
                          'objects': ()}
                apc.initObject(parent, o_info)

FWIW,
Florent

-- 
Florent Guillaume, Nuxeo (Paris, France)   CTO, Director of R&D
+33 1 40 33 71 59   http://nuxeo.com   fg at nuxeo.com


More information about the CMF-checkins mailing list