Re: [Zope] Accessing Zope REQUEST data from a Python module
(Wed, Dec 05, 2007 at 07:35:22PM -0500) Ken Winter wrote/schrieb/egrapse: > I'm customizing a product. To do what I'm trying to do, I need to be able > to access REQUEST data from within a Python module (not a script; a .py file > containing class and method definitions). Usually REQUEST is handed down to your method, as in: def mymethod(self, someparameter, REQUEST=None): and you then test for REQUEST not being None to determine if your method was called through a web browser or from another method. But... why don't you just follow one of the tutorials or sample products for making Zope Products? http://wiki.zope.org/zope2/DiskBasedProduct If I may say so myself, I'd recommend the newest one: http://papakiteliatziar.gr/BetaBoring Also very nice is the tutorial linked from the ZopeStarter page http://wiki.zope.org/zope2/ZopeStarter which is at http://www.upfrontsystems.co.za/courses/zope Regards, Sascha ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] Accessing Zope REQUEST data from a Python module
hi ken, very often you can replace context with self. so instead of context.REQUEST you use self.REQUEST. robert Ken Winter schrieb: > I'm customizing a product. To do what I'm trying to do, I need to be able > to access REQUEST data from within a Python module (not a script; a .py file > containing class and method definitions). > >>From within a script, a line like > > req = context.REQUEST > > does the job just fine. But when I put that line into my product module, I > get a message like: > > Name "context" not defined > > and I don't see any way to import that into my module. > > At (http://www.plope.com/Books/2_7Edition/AppendixB.stx#0-8), the Zope API > Reference describes the module "HTTPRequest", which includes the class that > it calls "HTTPRequest(BaseRequest)", which apparently is the equivalent of > REQUEST as described above. I have put this line into my module: > > from ZPublisher.HTTPRequest import HTTPRequest > > but now I don't know how to reference the request's contents. I put in this > line: > > req = HTTPRequest > > and print "req" to a debug file, and it shows: > > ZPublisher.HTTPRequest.HTTPRequest > > which I don't understand. I have tried a half-dozen ways (suggested by the > Zope API Reference) to get an actual property of the current HTTPRequest, > but without success. Examples: > > req['URL'] -> "TypeError: unsubscriptable object" > req.get('URL') -> "TypeError: unbound method get() must be called > with HTTPRequest instance as first argument (got str instance > instead)" > req.keys() -> "TypeError: unbound method keys() must be called with > HTTPRequest instance as first argument (got nothing instead)" > > The last two suggest that, while I have successfully imported the > HTTPRequest *class*, I haven't successfully gotten the current HTTPRequest > *instance*. I don't know how to do that. > > So, I need an answer to any one of these questions: > > 1. How can the Zope global name "context" be defined or imported into a > non-script Python module? > > 2. How can one get the current instance of the class "HTTPRequest" into a > non-script Python module? > > 3. If I'm looking in the wrong direction, what is the right way to make the > current REQUEST's data available in a non-script Python module? > > ~ TIA > ~ Ken > > > ___ > Zope maillist - Zope@zope.org > http://mail.zope.org/mailman/listinfo/zope > ** No cross posts or HTML encoding! ** > (Related lists - > http://mail.zope.org/mailman/listinfo/zope-announce > http://mail.zope.org/mailman/listinfo/zope-dev ) > begin:vcard fn:Robert Rottermann n: Rottermann;Robert email;internet:[EMAIL PROTECTED] tel;work:++41 31 333 10 20 tel;fax:++41 31 333 10 23 tel;home:++41 31 333 36 03 x-mozilla-html:FALSE version:2.1 end:vcard ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] Accessing Zope REQUEST data from a Python module
--On 5. Dezember 2007 19:35:22 -0500 Ken Winter <[EMAIL PROTECTED]> wrote: I'm customizing a product. To do what I'm trying to do, I need to be able to access REQUEST data from within a Python module (not a script; a .py file containing class and method definitions). From within a script, a line like req = context.REQUEST does the job just fine. But when I put that line into my product module, I get a message like: Name "context" not defined and I don't see any way to import that into my module. Either you have to pass down the request object down to your own code or you pass the current 'context' object down to your code and access the request object from their using context.REQUEST. Don't expect that the current REQUEST is magically available. So the solution for questions 1-3 is: pass down the parameters that you need from the location where you have them and from where you call your own code (which is likely a script or a template). -aj pgpQrHUYfam6N.pgp Description: PGP signature ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
[Zope] Accessing Zope REQUEST data from a Python module
I'm customizing a product. To do what I'm trying to do, I need to be able to access REQUEST data from within a Python module (not a script; a .py file containing class and method definitions). >From within a script, a line like req = context.REQUEST does the job just fine. But when I put that line into my product module, I get a message like: Name "context" not defined and I don't see any way to import that into my module. At (http://www.plope.com/Books/2_7Edition/AppendixB.stx#0-8), the Zope API Reference describes the module "HTTPRequest", which includes the class that it calls "HTTPRequest(BaseRequest)", which apparently is the equivalent of REQUEST as described above. I have put this line into my module: from ZPublisher.HTTPRequest import HTTPRequest but now I don't know how to reference the request's contents. I put in this line: req = HTTPRequest and print "req" to a debug file, and it shows: ZPublisher.HTTPRequest.HTTPRequest which I don't understand. I have tried a half-dozen ways (suggested by the Zope API Reference) to get an actual property of the current HTTPRequest, but without success. Examples: req['URL'] -> "TypeError: unsubscriptable object" req.get('URL') -> "TypeError: unbound method get() must be called with HTTPRequest instance as first argument (got str instance instead)" req.keys() -> "TypeError: unbound method keys() must be called with HTTPRequest instance as first argument (got nothing instead)" The last two suggest that, while I have successfully imported the HTTPRequest *class*, I haven't successfully gotten the current HTTPRequest *instance*. I don't know how to do that. So, I need an answer to any one of these questions: 1. How can the Zope global name "context" be defined or imported into a non-script Python module? 2. How can one get the current instance of the class "HTTPRequest" into a non-script Python module? 3. If I'm looking in the wrong direction, what is the right way to make the current REQUEST's data available in a non-script Python module? ~ TIA ~ Ken ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )