ANNOUNCE: JOTWeb 1.11, preview of new web application system.

Dave Cole djc at object-craft.com.au
Wed Jun 18 06:44:27 EDT 2003


> I didn't like that, at least as far as the documentation indicates
> to me, Albatross web pages have this context that has to be set up
> and maintained for each of the pages.  There's a fairly similar set
> of 10 lines of code that need to be set up for each page that you
> want to be dynamic.
> 
> For example, in JOTWeb to display a page with the current time in
> it, you would have a "code.py" file that contains:
> 
>    def currenttime():
>       import time
>       return(time.strftime('%H:%M:%S'))
> 
> And call that from an HTML file using:
> 
>    The current time is: <span tal:replace="code/currenttime"></span>
> 
> As a comparison, it seems to be that this code in Albatross would be
> a python module containing:
> 
>    #!/usr/bin/python
>    import os
>    from albatross import SimpleContext
> 
>    ctx = SimpleContext('.')
>    templ = ctx.load_template('time.html')
> 
>    import time
>    ctx.locals.currenttime = time.strftime('%H:%M:%S')
> 
>    templ.to_html(ctx)
> 
>    print 'Content-Type: text/html'
>    print
>    ctx.flush_content()
> 
> Then the HTML of:
> 
>    The current time is: <al-value expr="currentime">
> 
> It just seems like you have to cut and paste a lot of code in
> Albatross for every page you want to display.  But it's not just cut
> and paste, because you have to customize some parts of it (while
> leaving other parts alone).  JOTWeb tends to do a lot of that sort
> of stuff for you behind the scenes so that you don't have to think
> about them.

Or you could use one of the application classes to reduce the code
needed for each page.  Assuming you have more than one page in the
application.

>From where I sit it looks like JOTWeb makes more of the application
plumbing implicit than Albatross.  That is a good thing when the
plumbing fits the problem you are trying to solve.

When it comes down to it, the number of lines in a trivial application
is not why you use toolkits and frameworks.  You use a framework to
help construct a complex application.

- Dave

- - app.py - - - - - - - - - - - - - - - - - - - - - - - - - - - -

#!/usr/bin/python
import albatross
from albatross.cgiapp import Request

if __name__ == '__main__':
    app = albatross.ModularApp(base_url='app.py',
                               module_path='.',
                               template_path='.',
                               start_page='start',
                               secret='not telling')
    app.run(Request())

- - start.py - - - - - - - - - - - - - - - - - - - - - - - - - - -

import time

def page_display(ctx):
    ctx.locals.now = time.time()
    ctx.run_template('time.html')

- - time.html - - - - - - - - - - - - - - - - - - - - - - - - - - -

The current time is: <al-value expr="now" date="%H:%M:%S">

-- 
http://www.object-craft.com.au




More information about the Python-list mailing list