Your lev_fields_dict is not a dictionary but a set object (if you use curly braces without providing both keys and values separated by colons, you get a set). Neither sets nor dictionaries preserve order. In any case, you don't need a set -- just use a list (replace the curly braces with brackets to create a list comprehension).
Also, from a security perspective, it is dangerous to eval() code submitted by users -- don't do it. In fact, you don't need eval in any of the places you have used it. Instead of: eval('db.%s'%request.vars.lev_table) You can do: db[request.vars.lev_table] Anthony On Tuesday, August 12, 2014 6:16:57 AM UTC-4, Richard wrote: > > For updating a dynamically generated table I use a temporarily table and a > SQLFORM on that table. > This works fine except the sequence of the fields looks random to me. > > I use the following code: > > lev_fields_dict= { > Field( "d"+str(eval('db.%s'%request.vars.lev_table)[ > date_row.id]['lev_date']).replace("-", ""), > > db.local_ev_def[db(db.local_ev.lev_table_name==request.vars.lev_table).select().first().local_ev_def].data_type, > default=eval('db.%s'%request.vars.lev_table)[date_row.id > ]['lev_value'], > label = str(eval('db.%s'%request.vars.lev_table)[ > date_row.id]['lev_date']) > ) > for date_row in > eval('db(db.%s)'%request.vars.lev_table).select( > eval('db.%s'%request.vars.lev_table).id, > > orderby=eval('db.%s'%request.vars.lev_table).id) > } > > db.define_table('form_%s'%request.vars.lev_table, *lev_fields_dict) > form = SQLFORM(eval('db.form_%s'%request.vars.lev_table)) > > The fields in the temp table have random order. Does anybody know why? > Thanks, > Richard D > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.