On Wednesday, August 8, 2012 7:09:37 AM UTC-4, Jim Gregory wrote: > > Can custom_store and custom_retrieve take parameters when they are called > using Field, e.g.: > db.define_table('table', > Field('file', 'upload', custom_store=store_file(file, > db.table.new_filename), > custom_retrieve=retrieve_file(db.table.new_filename))? > Field('new_filename','string') > ) >
These attributes have to be callables, so you can't call them yourself. To pass additional custom arguments to a callable, just turn it into a lambda that takes the standard arguments and pass the additional arguments to your function within the lambda: Field('file', 'upload', custom_store=lambda file, filename, path: store_file(file, filename,path , db.table.new_filename), ...) When web2py calls the custom_store callable, it will pass three arguments (file, filename, and path), so your lambda must take three arguments. Within the lambda, you can then do whatever you want. You can pass any or all of the standard three arguments to your custom function, and you can pass additional arguments. In the example above, I passed the three standard arguments followed by a fourth custom argument, though it doesn't have to look like that (presumably you will at least want to pass the file as an argument). custom_retrieve takes two standard arguments, "name" and "path". Anthony --