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

Didrik Pinte pinted at tiscali.be
Wed Jun 2 00:47:37 EST 2004


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())
-------------- 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/20040601/ad5e2e5e/attachment.pgp>


More information about the Albatross-users mailing list