From: Noragen <no...@gm...> - 2009-03-18 18:21:34
|
Hi, i have two following problems: _1. problem:_ I make an import from a python module in a PSPPage. In this python i want to have following globals like req and res (request and response and perhaps other global stuff i dont remember yet) from a psp-page i can surely call the script with script(self) to get the objects within the script like def script(self) self.response().write("anytext") self.request().session.set("sessionparam","blub") but anyhow it is something like stupid to do it in every function less then have this in a global context. _2. problem: _I want to also have PSP-parsed .html-files. with adding .html to psp-handler it is not done. I tried it. Bug? Thanx and keep up the great work, Best Regards Tobias Franz |
From: Steve S. <agi...@gm...> - 2009-03-18 18:32:45
|
On 3/18/09, Noragen <no...@gm...> wrote: > > Hi, > > i have two following problems: > > *1. problem:* > I make an import from a python module in a PSPPage. > In this python i want to have following globals like req and res (request > and response and perhaps other global stuff i dont remember yet) > > from a psp-page i can surely call the script with script(self) to get the > objects within the script like > def script(self) > self.response().write("anytext") > self.request().session.set("sessionparam","blub") > > but anyhow it is something like stupid to do it in every function less then > have this in a global context. > Tobias, If I understand your question correctly you actually don't want a global contact because then that context would be shared with all other threads running in the appserver and you'd have requests overwritting that context. You really want a per thread context (which is per active request). Since an instance of the Servlet is created for each thread, you can assign data to the Servlet or your page instance and access it in the methods of that PSPPage subclass. So within the page "self" is your global context (but be certain to clear it at the beginning or end of each page to transaction to avoid accessing stale data in that thread). Best Regards, Steve |
From: Christoph Z. <ci...@on...> - 2009-03-18 19:42:49
|
Hi Tobias, concerning the first problem, I think Steve is right, the best way is to pass "self" around. You can also make the functions methods of the class that gets "self" as a parameter when instantiated. But the proper way would be to use <%@ page extends="MyPage"%>, where MyPage is a subclass of PSPPage, with additional functionality that you need in the particular page(s). You can also have multiple base classes or mixins. I think that's the "Webwarish" way to use PSP. Another option is using the PSP directive <%@ include ... %> instead of importing the file. By the way, the Page class has some convenience methods: Instead of self.response().write(...) you can simply use self.write(...), or isntead of self.request().session() you can use self.session(). See: http://www.w4py.org/WebKit/Docs/Source/Summaries/HTTPContent.html In the upcoming Webware 1.1 versions, it will also be possible to use self.response instead of self.response(). But the old notation will continue to work. Concerning the second problem, you're right - .html files are always served as they are, i.e. not parsed by PSP. The extensions that are parsed for PSP are returned by PSP.PSPServletFactory.extensions(). I'll make this configurable in the next version; for the time being you can patch this easily if you like. Concerning psp-handler, you should probably not use it in this version, I'm going to fix a problem here that has just been reported. -- Christoph |