Re: newbie (coming from java) question
Didrik Pinte <[email protected]> Wed, 02 Jun 2004 09:19:22 +0200
| Newsgroups | gmane.comp.web.albatross.general |
|---|---|
| Message-ID | <1086160762.4898.22.camel@geru-itea> |
Le mer 02/06/2004 à 02:32, Gregory Bond a écrit : > A couple of things spring to mind. > > [email protected] said: > > if ctx.req_equals('detail'): > > ctx.set_page('detail') > > if ctx.req_equals('recherche'): > > this should usually be elif - the set_page() call doesn't terminate the > page_process function (tho depending on the html template, you may never hit > the case where detail and recherche are both true...) Great ! First intersting information. > > > docInfoList = [] > > for result in container.searchContains('title',ctx.locals.title): > > docInfoList.append(result) > > Any particular reason this is not written as > docInfoList = container.searchContains(....) > (this is a general python nit not an albatross nit!) > searchContains is a generator, so it can write this like you suggest but the type of docInfoList is not a list but a generator ! > Are you expecting the ctx.metaData to be in the session? The code as written > will have a single metadata object that is recreated each time an HTTP request > is made (assuming this is a CGI and not, say, a mod_python script....) so any > changes made to the metaData object by the searchContents() function will be > lost. I'm expecting my metaData to be an application variable, so not a session one. It has to be a singleton for the all application serving all the request. Where shall I declare it ? > [email protected] said: > > My code does not work (what a shame !) > > Apart from the above, it looks reasonable enough to me. To go further, we'd > need a fair bit more info. What "does not work'? Does it throw exceptions? > What's broken? Here is the problem. In my ListPage class, i'm processing the request in the page_process() and create a docInfoList result. When page_display() is called, an error is raised saying that doclist cannot be found. If I process the request in the page_display() method, it works perfectly ! (see the second ListPage class below) Resulting question : how can I keep the docInfoList created in the page_process() so that it will be used in the page_diplay() ? I know I have to use the user session but how ? Thank you for the help. Didrik Pinte -------------------------------------------------------------- class ListPage: '''This page shows the list of results due to the search ''' name = 'list' def page_process(self,ctx): if ctx.req_equals('detail'): ctx.set_page('detail') if ctx.req_equals('recherche'): container = ctx.getContainer() docInfoList = [] for result in container.searchContains('title',ctx.locals.title): self.docInfoList.append(result) if len(self.docInfoList)<1 : ctx.locals.error = "No document found" ctx.set_page('error') else : ctx.locals.doclist = self.docInfoList ctx.add_session_vars('doclist') def page_display(self,ctx): ctx.load_template('headers.html').to_html(ctx) ctx.load_template('footer.html').to_html(ctx) ctx.run_template('list.html') ------------------------------------------------------------- Modified ListPage processing the request in the page_display() method class ListPage: '''This page shows the list of results due to the search ''' name = 'list' def page_process(self,ctx): if ctx.req_equals('detail'): ctx.set_page('detail') def page_display(self,ctx): ctx.load_template('headers.html').to_html(ctx) ctx.load_template('footer.html').to_html(ctx) if ctx.req_equals('recherche'): container = ctx.getContainer() docInfoList = [] for result in container.searchContains('title',ctx.locals.title): self.docInfoList.append(result) if len(self.docInfoList)<1 : ctx.locals.error = "No document found" ctx.locals.doclist = [] ctx.set_page('error') else : ctx.locals.doclist = self.docInfoList ctx.add_session_vars('doclist') ctx.run_template('list.html')
signature.asc
(application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) iD8DBQBAvX969Rlh4Zs4yBMRAmeLAJ4ki+yLrwc36Lde91aOSr1dbD3EwgCgkEue fK+f3fPJyESlR45WHQxPrZc= =B7n2 -----END PGP SIGNATURE-----