An attempt to use a python-based mini declarative language for form definition
carribeiro at gmail.com
Wed Sep 22 19:36:16 CEST 2004
I'm doing some experiments with mini declarative languages (as
explained by David Mertz in
http://www-106.ibm.com/developerworks/library/l-cpdec.html) in Python,
with the intention to use it as the mechanism to define data entry
forms. My final goal is to have a simple approach to automatic
generation of visual interfaces. The complete framework is rather big,
so let's us focus at this specific problem.
-- I would like to describe my data entry forms with plain Python
code. I don't want to use XML, dicts or other data-driven solution;
not because I don't like it, not because I don't know about it, only
because I want to try a different approach.
-- This is a simple code snippet of the intended form declaration:
nickname = TextBox(length=15, default="")
password = TextBox(length=10, default="", password=True)
name = TextBox(length=40, default="")
It's actually based to some extent on Ian Bicking's sqlobject library,
that uses a similar approach to build entity definitions. But there's
a catch: the class constructor receives a dict, and has no way to tell
the original ordering of the attributes in the original class. The
field names are passed in an arbitrary ordering, due to the use of the
-- I've tried using metaclasses or other similar magic; I've read the
tutorials, tried some code, and read sqlobject own implementation.
This is not a problem for sqlobject, because the order of the columns
in the database is totally isolated from the object representation.
But in my case, it is a problem, because I need the fields to be in
the correct order in the display.
My question is, there is any way to retrieve the class attributes in
the order they were declared? I could not find any; __setattr__ won't
work because the dict is constructed using the native dict type before
__new__ has a chance at it. Is there anything that I'm overlooking?
Consultoria em Projetos
mail: carribeiro at gmail.com
mail: carribeiro at yahoo.com
More information about the Python-list