reference - Web2py: Incorrect row when representing a referenced field -


it's rare find issue hasn't answered i've been searching 3 days , haven't found yet.

i'm aiming create page inputing records in 'spreadsheet' format. i've used inline editing in sqlform.grid this slice.

the problem i'm having when 1 of fields reference table, row being use in lambda function taking row of reference table rather row in grid.

here example: model

db.define_table('people',             field('name', 'string'),             format = '%(name)s',             )  db.define_table('animals',             field('name', 'string'),             field('pet_owner', 'reference people'),             format = '%(name)s',             ) 

controller

def index():     #process submitted form     if len(request.post_vars) > 0:         print request.post_vars         key, value in request.post_vars.iteritems():             (field_name,sep,row_id) = key.partition('_row_')             if row_id:                 db(db.animals.id == row_id).update(**{field_name:value})      db.animals.name.represent = lambda value,row:  sqlform.widgets.string.widget(db.animals.pet_owner,value, **{'_name':'name_row_%s' % row.id})      db.animals.pet_owner.represent = lambda value,row:  sqlform.widgets.options.widget(db.animals.pet_owner,value, **{'_name':'pet_owner_row_%s' % row.id})      grid = sqlform.grid(db.animals,                         selectable= lambda ids : redirect(url('animals',vars=request._get_vars)),                         )     grid.elements(_type='checkbox',_name='records',replace=none)  #remove selectable's checkboxes     return dict(grid=grid) 

at first appears grid working correctly. however, when inspecting drop-downs reference fields, if 2 consecutive rows have same value (e.g. 2 animals same owner) same row used in name (pet_owner_row_1) means value being passed process submitted form not integer (e.g. 3) integers separated pipes (e.g. '|3|3|').

i've confirmed issue changing represent db.animals.pet_owner.represent = lambda value,row: row shows exact same row data different animals.

here image showing inspector on form items: http://i.stack.imgur.com/oftf8.png

how can row id of grid's row rather id of reference?

any appreciated!

this bug has been fixed in master branch not released yet. in meantime, workaround temporarily change field integer type:

db.animals.pet_owner.type = 'integer' db.animals.pet_owner.represent = lambda value,row: sqlform.widgets.options.widget(     db.animals.pet_owner,value, **{'_name':'pet_owner_row_%s' % row.id}) 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -