So at the moment, what users are seeing is a controller presenting 
SQLFORM.grid of dataset records, and then in the 'view' argument to that 
controller for a particular record, the file field is shown as the output 
of the represent method of UploadWidget (so the word 'file' wrapped up with 
the download link, which is ignorant of the subfolder). It isn't obvious to 
me that there is a way to insert new_ds_id into that mechanism?

The new_ds_id (which is an integer) is stored in the record as 
datasets.dataset_id, so I've tried setting the uploadfolder in the model 
after the table definition using this:

db.datasets.file.uploadfolder = lambda id, row: os.path.join(request.folder, 
'uploads','datasets', str(row.dataset_id))

But that breaks - I get an error message: <type 
'exceptions.AttributeError'> 'function' object has no attribute 'endswith'. 
I think that is field.retrieve firmly expecting a string and trying to find 
the end character of the lambda function.

So, if that isn't possible, then I need a custom view of the record, which 
represents the file with a custom download function that I can pass 
new_ds_id to? 

On Friday, 2 February 2018 22:04:26 UTC, David Orme wrote:
> Hi,
> I'm collecting dataset files from users. There can be several versions as 
> problems with the files get fixed and I want to organise the uploaded files 
> by their common dataset id. So in my controller I do this:
> # set the upload directory locally
> upload_dir = os.path.join(request.folder, 'uploads', 'datasets', str(
> new_ds_id))
> db.datasets.file.uploadfolder = upload_dir
> # Setup the form
> form = SQLFORM(db.datasets, 
>                record = record, 
>                fields=['project_id', 'file'],
>                showid=False,
>                deletable=False,
>                button='Upload')
> That works really nicely and I just have to remember to use that path 
> where I need to find the file within the code. 
> However, I can't work out how to get the download controller to work with 
> the folder structure. For example, I'm currently using SQLFORM.grid to 
> provide a table of uploaded datasets, and when users click through to view 
> a particular record then they get the nice automatically generated file 
> download link. Unfortunately, that has no idea that there is the extra 
> component in the path, so it doesn't work.
> I've had a look at the source for, heading into 
> field.retrieve and it looks like I should be able to set a custom_retrieve, 
> but I can't find example usage.
>  Any suggestions?
> Many thanks,
> David

- (Documentation)
- (Source code)
- (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 
For more options, visit

Reply via email to