[Twisted-Python] Redirecting after form completion using woven

Donovan Preston dp at twistedmatrix.com
Fri Mar 7 13:35:18 EST 2003

On Friday, March 14, 2003, at 07:23 AM, Neil Blakey-Milner wrote:

> Hi,
> Two things:
> Firstly, using Twisted 1.0.3, when form submissions has occurred, it
> seems that the getData to build the form is done before the setData to
> make the changes.  This means that the _old_ information is in the
> forms, which is somewhat confusing.  For an example, use stikiwiki and
> edit a page.  It's entirely possible I'm using things incorrectly,
> though.

Here is what is happening: Since the views and controllers are 
triggered by traversing the DOM tree, if the view is above the 
controller, the view will render with the old data before the 
controller gets a chance to update the model with the new data. There 
are a couple of solutions, and the redirect is the best solution for 

1) Redirect the user after a successful controller commit, either to 
the same page, or a different page. This causes the page to get 
rerendered, and the new data will be available.

2) Notify the model that it's data has changed. The model will pass the 
notification on to the views which rely on the data, and the views will 
rerender themselves. There is an example of this technique in 
NewReality, and also in the unittests for woven.

> Secondly, how would I organise for a redirect to another page after my
> form has been parsed and data handled with setData?  Again, stikiwiki
> probably wants to redirect people to the page they've just edited or
> created instead of giving them an opportunity to edit it again.

Here's some code I use to do redirects; you can modify it for your 
needs. The only issue then is calling this code when the controller 
commits; if you're using input.Anything, you don't really have control 
over what happens when the controller gets some data and calls setData. 
I'll reread your code and come up with a suggestion.

def redirectToParent(request, now=1):
     """Redirect the current request to the immediate parent URL of the
     current request URL. Useful for redirecting from a tab URL to the
     main tab.
     parent = request.pathRef().parentRef()
     method, host, port = request.getHost()
     url = "http%s://%s%s/%s/" % (method is 'SSL' and 's' or '',
         getattr(request.site, 'serverName', host),
         getattr(request.site, 'serverPort', port) is 80 and '' or ':' + 
     if now:
     return url

> Thanks,
> Neil
> -- 
> Neil Blakey-Milner
> nbm at mithrandr.moria.org
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/enriched
Size: 3709 bytes
Desc: not available
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20030307/960552ce/attachment.bin 

More information about the Twisted-Python mailing list