[mod_python] templating (was: supporting modular mod_python extensions vs."folding" mod_psp)

Michael C. Neel neel at mediapulse.com
Tue Jun 10 17:23:30 EST 2003

     > > > <al-for iter="name" expr="keys">
     > > >     <tr>
     > > >          <td><al-value expr="name.value()"></td>
     > > >          <td><al-value expr="environ[name.value()]"></td>
     > > >     <tr>
     > > > </al-for>

I think this snippet doesn't show all of albatross; it acts much closer
to ezt.py than let on here.

In albatross, edna could do something like (warning, python-style sudo
code follows; do not attempt to run this at home):

In edna.py:

class edna_pages:

  def page_process(self, ctx):
    #called to process a page, ctx is the object with the request data
and methods
    if ctx.req_equals("show_dir"):
      #the "Show Directory" button was clicked
      file_list = get_files_in_dir(ctx.locals.directory) #defined
elsewhere, directory come from the broswer
      results = [] #list of results, will hold mp3 objects to pass to
      for file in file_list:
	  results.append(mp3(file)) # mp3 class defined elsewhere, gets
all the tag/size info

      ctx.locals.results = results # place results in the namespace of
the template

  def page_display(self, ctx):
    # load and run the template

in edny.html:
		<al-for expr="results" iter="row">
			<al-exec expr="mp3 = row.value()"> <!-- I do
this for sanity, we could very easily
use row.value().field instead -->
				<td><al-value expr="mp3.filename"></td>
				<td><al-value expr="mp3.size"> Kb</td>
				<td><al-value expr="'%0d:%02d' %
(mp3.minutes, mp3.seconds)"></td>

That's the basic idea, showing the seperation of logic and display of
Albatross.  There is a lot of cool stuff to Albatross as well, for
example it could easily with a few tags break the results into 30 per
page and provide prev and next buttons, but this give you the general


More information about the Mod_python mailing list