AnySQLFORM: one Form for Many Tables (even with same field names)

17 views
Skip to first unread message

Jurgis Pralgauskis

unread,
Jan 15, 2017, 10:46:58 AM1/15/17
to web2py-users
Hi, 

I try to develop layer over SQLFORM
which would fully preserve field info (even better than in book example)

Ii call it AnySQLFORM 

I want it to return Row object:
in my "test" example: 

the fields/expressions are:
        db.auth_user.first_name, 
        db.auth_user.last_name, 
        
        db.auth_user.id,
        
        db.auth_permission.table_name,
        
        Field( 'somefield' ),
        Field('user_id', 'reference auth_user', requires=IS_IN_DB(db,db.auth_user.id, '%(first_name)s %(last_name)s')),
        FormField(db.auth_user.first_name + db.auth_user.last_name, name='full_name'),


if form.vars are
<Storage {'auth_user__last_name': 'Dow', 'auth_user__first_name': 'John',
'no_table__somefield': 'asdf',
'auth_permission__table_name': 'bla',
'auth_user__id': 4,
'full_name': 'ohn',
'no_table__user_id': 4,
'auth_permission__id': 3}>





the self.vars_as_Row() takes request.vars and returns

<Row {'auth_user': {'first_name': 'John', 'last_name': 'Dow', 'id': '4'},
           'auth_permission': {'table_name': 'bla', 'id': '3'}, 
           'no_table': {'user_id': '2', 'somefield': 'asdf'}, 
            '_extra': {'(auth_user.first_name || auth_user.last_name)': 'ohn'}}>

I want to use it primarily as search from, so it can have even Expresssion instead of Field.

***
I implemented FormField as extension of Field, 
and AnySQLFORM as proxy to form_factory result... 

not sure if I do it nicely -- so review/advice is welcome :) 
 
Reply all
Reply to author
Forward
0 new messages