[albatross-users] newbie (coming from java) question

Didrik Pinte pinted at tiscali.be
Wed Jun 2 17:19:22 EST 2004


Le mer 02/06/2004 à 02:32, Gregory Bond a écrit :
> A couple of things spring to mind.
> 
> pinted at tiscali.be 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 ?

> pinted at tiscali.be 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')
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Ceci est une partie de message num?riquement sign?e.
URL: <http://www.object-craft.com.au/pipermail/albatross-users/attachments/20040602/ae84d848/attachment.pgp>


More information about the Albatross-users mailing list