Re: Redirecting from rend method of some fragment.

Jean-Paul Calderone <[email protected]> Thu, 19 Jun 2008 08:16:58 -0400
Newsgroups gmane.comp.python.quotient.dev
Message-ID <20080619121658.4714.1114276637.divmod.quotient.10783@ohm>
On Thu, 19 Jun 2008 15:11:00 +0300, Eugene Chernyshov <[email protected]> wrote:
>class RegisterFragment(BaseFragment):
>#.... There was something
>    def rend(self, context, data):
>        args=inevow.IRequest(context).args
>        self.analyzeArgs(args)
>        if self.fullData:
>request=url.URL.fromString(realm.nyaServerURL).child('__register__').add("username", 
>args['username'][0]).add("password", args['password'][0])
>            return 
>client.getPage(str(request)).addCallbacks(callback=self.onAccept, 
>errback=self.onConflict, callbackArgs=[context, data], errbackArgs=[context, 
>data])
>        return BaseFragment.rend(self, context, data)
>    def onAccept(self, result, context, data):
>        request=inevow.IRequest(context)
>link=url.root.urlaccessor(context).clear().child('__login__').add("username", 
>request.args['username'][0]).add("password", request.args['password'][0])
>        request.redirect(str(link)) # <------ doesn't work at all
>        request.finish()
>        return BaseFragment.rend(self, context, data)
>    def onConflict(self, result, context, data):
>        self.errorCase='conflict'
>        return BaseFragment.rend(self, context, data)
>
>
>How can I make subj?
>

Redirecting with a Fragment is tricky.  request.redirect() has to be
able to set a response header.  If it can't, it won't work (unfortunately,
it fails silently).  If bytes for the response body have already been
written, then you can't set set anymore response headers.  Since a Fragment
is only part of a page, the chances are good that some other code which
is also part of the page has already written some of the response body.

So, you need to be careful not to write anything to the request before you
do the redirect.

If you do that and it still doesn't work, please post again with more
details.

Jean-Paul