I am sure you can do it all with Python but I think you should put
your dictionaries into underscored files and construct databases in
non-underscored.

If I uderstood you correctly you want to store a lot of meta-data with
your fields/tables definitions. Incidentally I did the same in order
to 'DRY' - I have one place where define all of my data requirements:
- data fields for database
- data fields for CSV file import
- flags that field is to be visible in user interface
- pre-processing function calls to be invoked during data import
before data is recorded to DB
- etc.
I simply added a class to my underscored file:

class AdvantageField(SQLField):
    def __init__(self, *args, **keys):
        def adv_key_parser(key_name, default_value):
            if keys.has_key(key_name):
                r = keys[key_name]
                del keys[key_name]
            else:
                r = default_value
            return r

        #the following setters clean out my properties from
AdvantageField's
        #so that I can safely init SQLField:

        self.adv_display = adv_key_parser('adv_display', False)
#display field value in data_storage view?
        self.adv_input = adv_key_parser('adv_input', False)
#field must be read from input file?
        self.adv_accumulate = adv_key_parser('adv_accumulate', False)
#fields will be added together and stored to accumulator
        #.... etc.
        #now I init my SQLField
        #args[0].m is a trick that allows me to not repeat myself with
translations
        #I pass field name to AdvantageField as T('field name')
        #this makes static inclusion of a string to be translated, and
therefore it appears in translations GUI
        SQLField.__init__(self, args[0].m, *args[1:], **keys)


then I can create my data table with meta definitions:

header_fields = (
    AdvantageField(T('UID'), 'string', adv_input=True,
adv_display=True),
    AdvantageField(T('NAME'), 'string', length=255, adv_input=True,
adv_display=True,
                    adv_translit="NAME_F_TRANSLIT NAME_I_TRANSLIT
NAME_O_TRANSLIT"),
    AdvantageField(T('DEBT'), 'double', adv_input=True,
adv_accumulate='TOTAL_DEBT', adv_display=True),
....

then I can define database table:

db.define_table('headers',
    *header_fields
)

but still can access my meta-data in controllers and other code:

fields_to_display = [f.name for f in header_fields if f.adv_display]

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to