A bit of code is better than a thousand words. Help us to improve the docs 
on your own words for the online book......

let's resume the plain old person - dog model.....
db.define_table('person',
    Field('name', requires=IS_NOT_EMPTY())
    ,format = '%(name)s'
    )
db.define_table('dog',
    Field('owner_name', 'reference person'),
    Field('name', requires=IS_NOT_EMPTY())
    )



ondelete, oncreate, onupdate both on SQLFORM.grid and SQLFORM.smartgrid 
accept parameters in the same exact way.

def test():
    grid = SQLFORM.grid(db.person, ondelete=ondelete_test, onupdate=
onupdate_test, oncreate=oncreate_test)
    #grid = SQLFORM.smartgrid(db.person, ondelete=ondelete_test, 
onupdate=onupdate_test, oncreate=oncreate_test)
    return dict(grid=grid)

def ondelete_test(table_involved, id_of_the_deleted_record):
    print table_involved
    print id_of_the_deleted_record

def onupdate_test(form):
    print form.vars
    """
    <Storage {'owner_name': '1', 'name': 'john dog 1 - modified', 
'delete_this_record': None, 'id': 3}>
    or
    <Storage {'name': 'john - modified', 'delete_this_record': None, 'id': 
1}>
    """

def oncreate_test(form):
    print form.vars
    """
    <Storage {'name': 'new niphlod', 'id': 4L}> or
    <Storage {'owner_name': '3', 'name': 'niphlod dog 4', 'id': 8L}>
    """



so, play with it .... case 1) is for grid and case 2) for smartgrid.

find out yourself that.....
Ondelete: 1) and 2) takes 2 parameters: the first one is the table instance 
and the second one is the id of the "soon to be deleted" record. 
"table_involved" is actually db.person for 1) and db.person or db.dog for 
case 2) ... you can fetch the "soon to be deleted record" using the simple 
syntax "table_involved(id_of_the_deleted_record)" as in "db.person(2)"

Onupdate: 1) and 2) take one parameter only: the form actually submitted, 
with all the vars: it's up to you to "choose" what table are the vars from. 
It's EXACTLY the same onupdate callback that can be passed to a simple 
SQLFORM.process()

Oncreate: 1) and 2) take one parameter only: the form actually submitted, 
with all the vars. it's up to you to "choose" what table are the vars from. 
It's EXACTLY the same oncreate callback that can be passed to a simple 
SQLFORM.process()

Clearer now ?


-- 



Reply via email to