Re: [Zope] newbie question: Redirect from Python?
OK, this seems to work. def manage_addMyProduct(self, id, title='', REQUEST=None, RESPONSE=None): self._setObject(id, MyProduct(id, title)) if REQUEST is not None: whereto= REQUEST['URL3'] RESPONSE.redirect(whereto, lock=0) -- .paul winkler.. slinkP arts: music, sound, illustration, design, etc. web page: http://www.slinkp.com A member of ARMS: http://www.reacharms.com ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] newbie question: Redirect from Python?
Dieter Maurer wrote: > > If you need it in the constructor, then you must > either pass in an object that is tied by acquisition > or REQUEST or RESPONSE itself, > or you must move the call out into the method > "manage_afterAdd" (where the object already is tied in). Well, I don't have that method. Went to learn about what people use it for - searched for manage_afterAdd on zope.org and got nothing at all??? Anyway, I'm now redirecting in manage_Add and it seems to work fine. -- .paul winkler.. slinkP arts: music, sound, illustration, design, etc. web page: http://www.slinkp.com A member of ARMS: http://www.reacharms.com ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] newbie question: Redirect from Python?
Paul Winkler writes: > I want the user to be sent to a particular URL after calling the > product's manage_add method. How can I do that? > The URL I want is REQUEST['URL3']. > > I've tried RESPONSE.redirect(REQUEST['URL3']) but that's not it - the > RESPONSE doesn't seem to exist here. I hope, you do not need the redirect in your constructor as in the constructor the newly created object is not yet tied into the web site hierarchy via acquisition. If the object, say "self", is already tied in, then you can use "self.REQUEST.RESPONSE.redirect()". If you need it in the constructor, then you must either pass in an object that is tied by acquisition or REQUEST or RESPONSE itself, or you must move the call out into the method "manage_afterAdd" (where the object already is tied in). Dieter ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] newbie question: Redirect from Python?
Phil Harris wrote: > > You need to be careful when redirecting from an external Python wotsit. > > RESPONSE.redirect raises an exception which can make the transaction get > rolled back. > > This seems not to happen when called from dtml but I've seen it happen from > an external Python wotsit. > > Note: > > My use of wotsit above in no way has a bearing on the new name for the > Python Methods/ZMethods/Script or whatever the hell they are called now. ;) Thanks for the warning. Does this only happen in certain circumstances? I'm not using an External Method or a Python Script or whatever those things are called now. I'm doing it in a Product. Does that matter? .paul winkler.. slinkP arts: music, sound, illustration, design, etc. web page: http://www.slinkp.com A member of ARMS: http://www.reacharms.com ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] newbie question: Redirect from Python?
Michel Pelletier wrote: > > Paul Winkler wrote: (snip) > > Looking through various Zope docs, I thought RESPONSE.redirect might > > work, but RESPONSE is not mentioned anywhere in Boring.py. Boring > > only uses REQUEST. > > So pass it RESPONSE: > > def manage_addMyProduct(self, blah, blah, REQUEST=None, RESPONSE=None): > ... > > The publisher will automaticaly pass you RESPONSE if you ask for it as a > method argument. Now use RESPONSE.redirect. Aha, thanks. I didn't know that about the publisher. Now I'm afraid I'm too stupid to see how to use RESPONSE.redirect after reading the description in the Zope Book API appendix. My method now looks like this: def manage_addMyProduct(self, id, title='', REQUEST=None, RESPONSE=None): """Add a MyProduct instance to the folder.""" self._setObject(id, MyProduct(id, title)) if REQUEST is not None: whereto= REQUEST['URL3'] return RESPONSE.redirect(whereto, 0) That just prints the URL as a string. OK, so maybe I'm not supposed to use the return value? So I try it like this: def manage_addMyProduct(self, id, title='', REQUEST=None, RESPONSE=None): """Add a MyProduct instance to the folder.""" self._setObject(id, MyProduct(id, title)) if REQUEST is not None: whereto= REQUEST['URL3'] RESPONSE.redirect(whereto, 0) Now when I submit the form, I can wait for a result forever and not get anything. How am I *really* supposed to do it? -- .paul winkler.. slinkP arts: music, sound, illustration, design, etc. web page: http://www.slinkp.com A member of ARMS: http://www.reacharms.com ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] newbie question: Redirect from Python?
You need to be careful when redirecting from an external Python wotsit. RESPONSE.redirect raises an exception which can make the transaction get rolled back. This seems not to happen when called from dtml but I've seen it happen from an external Python wotsit. Note: My use of wotsit above in no way has a bearing on the new name for the Python Methods/ZMethods/Script or whatever the hell they are called now. ;) Phil [EMAIL PROTECTED] - Original Message - From: "Paul Winkler" <[EMAIL PROTECTED]> To: "Zope mailing list" <[EMAIL PROTECTED]> Sent: Monday, November 27, 2000 6:26 PM Subject: [Zope] newbie question: Redirect from Python? | I want the user to be sent to a particular URL after calling the | product's manage_add method. How can I do that? | The URL I want is REQUEST['URL3']. | | I've tried RESPONSE.redirect(REQUEST['URL3']) but that's not it - the | RESPONSE doesn't seem to exist here. | | | -- | .paul winkler.. | slinkP arts: music, sound, illustration, design, etc. |web page: http://www.slinkp.com | A member of ARMS: http://www.reacharms.com | | ___ | Zope maillist - [EMAIL PROTECTED] | http://lists.zope.org/mailman/listinfo/zope | ** No cross posts or HTML encoding! ** | (Related lists - | http://lists.zope.org/mailman/listinfo/zope-announce | http://lists.zope.org/mailman/listinfo/zope-dev ) ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] newbie question: Redirect from Python?
Paul Winkler wrote: > > seb bacon wrote: > > > > * Paul Winkler <[EMAIL PROTECTED]> [001127 19:54]: > > > I want the user to be sent to a particular URL after calling the > > > product's manage_add method. How can I do that? > > > The URL I want is REQUEST['URL3']. > > > > > > I've tried RESPONSE.redirect(REQUEST['URL3']) but that's not it - the > > > RESPONSE doesn't seem to exist here. > > > > sounds alright to me. are you calling it in quotes, e.g. > "RESPONSE.redirect(REQUEST['URL3'])"> ? > > > > you shouldn't have to use the REQUEST to look up the variable, either: > > > > Thanks for the reply. > OK, I didn't phrase the question correctly. > > I think it boils down to this: > If I have a string that represents a URL, can I define a method of my > product (in python, not in DTML) that redirects the browser to that > URL? > > More details: > > My product code is based on Boring (like most newbies I guess). > But manage_addBoring() does not do quite what I want. It returns > self.manage_main(self, REQUEST), so they end up at a long and ugly URL > that isn't where I want them to be anyway. > > Example: > the user is at: > > http://localhost.localdomain:8080/Members/bobby > > Bobby then clicks on a button I've provided that says "Add Test > Product". That sends him to the add form I've created. When Bobby > submits the request from this form, the product is added and he's sent > to > > >http://localhost.localdomain:8080/Members/bobby/manage_addProduct/MyProduct/manage_main > > ...because manage_addMyProduct returns self.manage_main > So I understand what's happening, but it's not what I want. > I don't want to send him there, I want to send him back to > > http://localhost.localdomain:8080/Members/bobby > > So how can I do that from within the manage_addMyProduct method > definition? > The method gets a REQUEST argument, and I know that REQUEST['URL3'] is > what I want because if I return that string, it prints the URL I want. > > I could do it by returning an HTML page with a redirect in the > but that seems like a horribly ugly solution. > > Looking through various Zope docs, I thought RESPONSE.redirect might > work, but RESPONSE is not mentioned anywhere in Boring.py. Boring > only uses REQUEST. So pass it RESPONSE: def manage_addMyProduct(self, blah, blah, REQUEST=None, RESPONSE=None): ... The publisher will automaticaly pass you RESPONSE if you ask for it as a method argument. Now use RESPONSE.redirect. -Michel ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] newbie question: Redirect from Python?
seb bacon wrote: > > * Paul Winkler <[EMAIL PROTECTED]> [001127 19:54]: > > I want the user to be sent to a particular URL after calling the > > product's manage_add method. How can I do that? > > The URL I want is REQUEST['URL3']. > > > > I've tried RESPONSE.redirect(REQUEST['URL3']) but that's not it - the > > RESPONSE doesn't seem to exist here. > > sounds alright to me. are you calling it in quotes, e.g. "RESPONSE.redirect(REQUEST['URL3'])"> ? > > you shouldn't have to use the REQUEST to look up the variable, either: > Thanks for the reply. OK, I didn't phrase the question correctly. I think it boils down to this: If I have a string that represents a URL, can I define a method of my product (in python, not in DTML) that redirects the browser to that URL? More details: My product code is based on Boring (like most newbies I guess). But manage_addBoring() does not do quite what I want. It returns self.manage_main(self, REQUEST), so they end up at a long and ugly URL that isn't where I want them to be anyway. Example: the user is at: http://localhost.localdomain:8080/Members/bobby Bobby then clicks on a button I've provided that says "Add Test Product". That sends him to the add form I've created. When Bobby submits the request from this form, the product is added and he's sent to http://localhost.localdomain:8080/Members/bobby/manage_addProduct/MyProduct/manage_main ...because manage_addMyProduct returns self.manage_main So I understand what's happening, but it's not what I want. I don't want to send him there, I want to send him back to http://localhost.localdomain:8080/Members/bobby So how can I do that from within the manage_addMyProduct method definition? The method gets a REQUEST argument, and I know that REQUEST['URL3'] is what I want because if I return that string, it prints the URL I want. I could do it by returning an HTML page with a redirect in the but that seems like a horribly ugly solution. Looking through various Zope docs, I thought RESPONSE.redirect might work, but RESPONSE is not mentioned anywhere in Boring.py. Boring only uses REQUEST. -- .paul winkler.. slinkP arts: music, sound, illustration, design, etc. web page: http://www.slinkp.com A member of ARMS: http://www.reacharms.com ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] newbie question: Redirect from Python?
* Paul Winkler <[EMAIL PROTECTED]> [001127 19:54]: > I want the user to be sent to a particular URL after calling the > product's manage_add method. How can I do that? > The URL I want is REQUEST['URL3']. > > I've tried RESPONSE.redirect(REQUEST['URL3']) but that's not it - the > RESPONSE doesn't seem to exist here. sounds alright to me. are you calling it in quotes, e.g. ? you shouldn't have to use the REQUEST to look up the variable, either: ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
[Zope] newbie question: Redirect from Python?
I want the user to be sent to a particular URL after calling the product's manage_add method. How can I do that? The URL I want is REQUEST['URL3']. I've tried RESPONSE.redirect(REQUEST['URL3']) but that's not it - the RESPONSE doesn't seem to exist here. -- .paul winkler.. slinkP arts: music, sound, illustration, design, etc. web page: http://www.slinkp.com A member of ARMS: http://www.reacharms.com ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )