[Zope-CMF] How to tell what action has been called
seb bacon
seb@jamkit.com
Thu, 11 Oct 2001 11:34:38 +0100
How can I find out which action has been called on an object just
before its publication? At the moment, I'm using a BeforeTraverse
hook to snarf the TraversalRequestNameStack. Then I'm walking the
stack comparing each method in turn to each method in the object's
TypeInfo actions list. When they match I have found the correct
action.
This feels very wrong, and very inefficient. Can anyone think of any
better ways of doing this?
def __call__(self, client, request, response=None):
stack = request['TraversalRequestNameStack']
myAction = None
stack.reverse()
ti = self.getTypeInfo()
if ti is not None:
actions = ti.getActions()
for stackItem in stack:
for a in actions:
if a['action'] == stackItem:
myAction = a['id']
break
# do stuff with myAction, before I get published
In case you're wondering what I'm up to, here's an explanation, which
is entirely optional reading ;-)
A question which arises when making composite content is what action
should be performed on components which are in slots.
In the following example, FooTemplate is a page layout which contains
an image and a document in slot 1 and slot 2. When the 'view' action
is performed on the FooTemplate, what should the action be which is
performed on the slots?
FooTemplate/view
|
`- image_1/view
|
`- document_1/view
In this diagram, I'm having the slots perform the same action as the
Template, but I think the concept is much more powerful (and
generalised) if you can map Template actions to slot actions
arbitrarily.
I've set up a kind of actions mapping registry, but now I need to know
what action has been performed on the Template before it is published,
in order to look up the information for its respective slots.
cheers,
seb