That's brilliant, thank you! The bit I didn't know about was ICurrentSegments. I *think* I see how this works :-)
Peter. On Fri, Jan 4, 2013, at 16:32, Phil Mayers wrote: > On 04/01/13 16:00, Peter Westlake wrote: > > I'm using nevow.guard, and when someone logs in I would like to send > > them to the URL they originally typed. It's possible to do this by > > posting to the URL guard.LOGIN_AVATAR + other stuff, e.g. to go to > > http://example.com/foo/bar after logging in, the login page should post > > to http://example.com/__login__/foo/bar. This works nicely. The problem > > is, the login page doesn't know that the user was trying to go to > > foo/bar. How can it get that information? I would have thought that it > > would be available as the segments argument in locateChild, but for some > > reason it isn't. Before logging in, the segments argument is always > > empty. > > Looking at some *very* old code, we have something like this: > > > class LoginPage(rend.Page): > > def locateChild(self, c, s): > return self, [] > > def data_misc(self, ctx, data): > u = url.root.child(guard.LOGIN_AVATAR) > for path in inevow.ICurrentSegments(ctx): > u = u.child(path) > return { > 'action': u > } > > > docFactory = loaders.stan( > T.html[ > T.head[ > T.title['ICT Host Database - not logged in'], > ], # head > T.body(data=T.directive('misc'), render=T.directive('mapping'))[ > T.form(action=T.slot('action'), method='post')[ > ... > > components.registerAdapter(LoginPage, ihdb.IAnonymous, inevow.IResource) > > > i.e. the component you register as the adapter for the "Anonymous" user > needs a "data" method that gathers the url segments, and you reference > that data method from the "action" value of the login form - so the form > will be posted to: > > /$guard.LOGIN_AVATAR/original/url/goes/here > > _______________________________________________ > Twisted-web mailing list > [email protected] > http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web _______________________________________________ Twisted-web mailing list [email protected] http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
