newbie (coming from java) question

Didrik Pinte <[email protected]> Tue, 01 Jun 2004 16:47:37 +0200
Newsgroups gmane.comp.web.albatross.general
Message-ID <1086101257.4898.7.camel@geru-itea>
Hi,

I'm running a little website with albatross and have some
question/problems with the basic albatross concepts.

I'm used to Java Servlets vocabulary and need some help.

Here is what I need to do


I have an Python object managing searches in my dbxml. I need that
object in the "application context", so that it will be used from
anywhere in the app.

Then, when the client request a documentname, i search for the doc, and
depending on the result, i make appear the right page with the results.
With what I understand, I've created a class ListPage that use the
page_process() method to define what to do. So it searches for the
documents, if no document found, redirect the user to an ErrorPage,
otherwise, I want to store the doclist in the "session context" so that
it will be used in the page_display() method.

My code does not work (what a shame !).

Can someone have a look on this ?

Thank you in advance.

Didrik Pinte

Here is the code :
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):
                docInfoList.append(result)
            if len(docInfoList)<1 :
                ctx.locals.error = "No document found"
                ctx.locals.doclist = []
                ctx.set_page('error')
            else :
                ctx.locals.doclist = 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')

class ErrorPage:
    ''' Managing errors
    '''
    
    name = 'error'

    def page_display(self,ctx):
        ctx.run_template('error.html')

class ApplicationContext(SimpleAppContext):
    '''Initialises the context of the application and defines some
methods to be used in all the page
    '''

    metaData = None

    def _initialiseContainer(self):
        self.metaData = MetaData('mila.dbxml')
        
    def getContainer(self):
        if self.metaData == None:
            self._initialiseContainer()
        return self.metaData

class App(SimpleSessionApp):

    def __init__(self):
        SimpleSessionApp.__init__(self,
                           base_url='application.py',
                           template_path='.',
                           start_page='search',
                           secret='-=-secret-=-',
                           session_appid='metadata')
        for page in (SearchPage,ListPage,DetailPage,ErrorPage):
            self.register_page(page.name, page())

    def create_context(self):
        return ApplicationContext(self)

if __name__ == '__main__':
    app.run(Request())
signature.asc (application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQBAvJcJ9Rlh4Zs4yBMRAs7HAKCs/tlb9f0wyqTInGK9E7+2a3kKdACdG7dW
+2fAltiixzhgtbQbOfhjOb0=
=k1tU
-----END PGP SIGNATURE-----