[Product-Developers] Re: Traversing from a z3c.form action handler

cewing cewing at u.washington.edu
Sun Feb 14 18:24:21 UTC 2010

Martin Aspeli wrote:
> Cristopher Ewing wrote:
>> I'm trying to work out a way to have the action in a z3c.form based form
>> send the user to the built-in plone content_status_history form, similar
>> to how the 'Change State' action on folder_contents works.
>> For some reason I can't seem to find any examples of making this work.
>> Can someone help me figure out what the right way is to accomplish this
>> task? I need to use the form action handler to set the 'paths' parameter
>> on the request, so that request.get('paths') will return the paths of
>> the objects I've selected in my form. I can do that, but once it's done,
>> how to I traverse on to the content_status_history form? That part has
>> me stumped.
> Did you try self.request.response.redirect(self.context.absolute_url() + 
> '/content_status_history') ?

It was 3 am when I got to this point, but yes, that was the first thing I
tried.  Response.redirect appears to lose the data I've set on the request
in my form action.  I remember reading a blog post at one point about using
a traversal technique instead of response.redirect to keep the original
request and all its data intact as you move from one page to another.  It
seems that ControllerPageTemplates must use something like this, since all
of their metadata contain references to 'TraverseTo'.  

Martin Aspeli wrote:
>> restrictedTraverse will get me the FSControllerFormTemplate object,
>> which is nice enough, but calling that just returns the html of the form
>> without actually publishing it.
> Yes, that's how restrictedTraverse() works. You could just return this 
> HTML, but the URL would be wrong.

I'm not terrifically concerned about the URL being wrong, but I've not
managed to have returning the URL do anything.  

Here's what I have in the action so far:

class AnimalTable(HydraCrudEditForm):
    label = _(u'My Animals')
    @button.buttonAndHandler(u'Change State', name='state_change')
    def handle_state_change(self, action):
        """ traverse to the content_status_share form for processing
        true_context = self.context.context
        selected = self.selected_items()
        paths = []
        if selected:
            paths = [item.absolute_url_path() for id, item in selected]
            self.request.form['paths'] = paths
            path = true_context.absolute_url_path() +
            state_view = true_context.restrictedTraverse(path)
            return state_view()
            IStatusMessage(self.request).add("No animals selected",

Unfortunately, that just ends up by reloading the original form without any
indication that anything has happened.  

I'm obviously missing the right thing to do here, but I just can't seem to
see the forest for the trees.  Any pointers would be much appreciated.


View this message in context: http://n2.nabble.com/Traversing-from-a-z3c-form-action-handler-tp4569560p4571094.html
Sent from the Product Developers mailing list archive at Nabble.com.

More information about the Product-Developers mailing list