[Zope-CMF] How do I get the action for 'folderContents'?
Grégoire Weber
gregoire.weber@switzerland.org
Thu, 04 Apr 2002 01:24:58 +0200
Hi Tres,
hi all,
to be sure not to run into problems caused by actions without a 'id'
(e.g. workflow actions) the following corrected code should be used.
I replaced x['id'] by x.get('id', None).
<CODE>
# workaround: get the absolute action path of an action not registered by an
# object in the portal_types tool like the 'folderContents' action:
actions_list = []
for actions in
context.portal_actions.listFilteredActionsFor(context).values():
actions_list.extend(actions)
action_path = filter(lambda x:x.get('id', None) == 'folderContents',
actions_list)[0]['url']
</CODE>
Greetings, Greg
> Grégoire Weber wrote on Thu, 04 Apr 2002 00:19:59 +0200
>
> tanks for your snippet and your prompt answer, it guided me to the working=
> solution below.
>
> > There isn't any API for fetching a single action information object
> > from the tool; we should perhaps add one. As a workaround, try::
> >
> > actions = context.portal_actions.listFilteredActionsFor( context )
> > fc_actions = map( lambda x: x['id'] == 'folderContents',=
actions )
> > if fc_actions:
> > fc_action = fc_actions[0]
>
> The follwing snippet works for CVS-Versions of march 2002 (post CMF 1.2):
>
> <CODE>
> # workaround: get the absolute action path of an action not registered by
an
> # object in the portal_types tool like the 'folderContents' action:
> actions_list = []
> for actions in
context.portal_actions.listFilteredActionsFor(context).values():
> actions_list.extend(actions)
> action_path = filter(lambda x:x['id'] == 'folderContents',
actions_list)[0]['url']
>
> # just for information (normal way): get an action of an object registered=
> # with the object:
> action_path = context.getTypeInfo().getActionbyId('edit')
> </CODE>
>
> Greg
_____________________________________
Grégoire Weber
Rigistr. 31
CH-8006 Zürich
Switzerland
phone: +41-(0)1-361 66 11
mobile: +41-(0)79-44 11 457
mailto:gregoire.weber@switzerland.org