[albatross-users] Form state problem

Michael Neel neel at mediapulse.com
Wed Oct 30 15:24:21 EST 2002


> Very nice.  How hard was it building the extension tag?

Very easy.  In fact I did the extension tag in my second day of using
albatross.

Since Gregory might have use here is the alx_sql.py code (the database
connection is made in globals.py):

..........................................
import albatross, MySQLdb
from globals import db

class Sql(albatross.EmptyTag):
    name = 'alx-sql'

    def __init__(self, ctx, filename, line_num, dict):
        self.db_cursor = db.cursor()
        albatross.EmptyTag.__init__(self, ctx, filename, line_num, dict)

    def to_html(self, ctx):
        stmt = self.get_attrib('stmt')
        args = self.get_attrib('args')
        ctx.locals.db_cursor = self.db_cursor

        try:
            if args is None:
                ctx.locals.db_cursor.execute(stmt)
            else:
                ctx.locals.db_cursor.execute(stmt, eval(args,
ctx.locals.__dict__))
        except MySQLdb.DatabaseError, errstr:
            self.raise_error("Database Error: " +  str(errstr))

...........................................

Not a lot, but gets the job done.  I used MySQLdb, but should work with
any DB API 2.0 driver without much change.

Mike




More information about the Albatross-users mailing list