It seems that cascade deletion of uploaded files works fine only if there 
is no definition of 'uploadfolder'.

At db.py
db.define_table('person',
    Field('name', requires=IS_NOT_EMPTY(), required=True),
    Field('nickname', 'string', required=True  ),
    format = '%(name)s'
    )

def define_folder_name():
    up_folder =  os.path.join(request.folder,'uploads')
    if request.args(1)=='files.person' and request.args(2):
        up_folder =  os.path.join(up_folder, 
db.person(request.args(2)).nickname 
)
    return up_folder
db.define_table('files',
                Field('person',db.person,label='Analysis Request',
                      ondelete='CASCADE', required=True, writable=False,
                      represent=lambda anID,row: db.person(anID).nickname  
                      ),            
                Field('myfile','upload',length=100, required=True,autodelete
=True,
                      uploadfolder=define_folder_name(), 
                      uploadfield=True, # keeps file in folders, not into 
 DB blogs
                      label='File',
                      ),
                Field('description','text', required=True, label=
'Description',                
                      ),
                )

At default.py:
def test():
    grid = SQLFORM.smartgrid(db.person, linked_tables=['files'] )
    return dict(grid=grid)

If a user is created, let's say: name='Tom' and nickname='Tom',
and a file is uploaded to his 'files', then a directory Tom is being 
created under 'uploads' dir.
If we now delete the user Tom pressing the 'Delete' button, the records are 
removed by the database form tables person and files, but the 
uploads/Tom/files.myfile.xxxx.bin
is still there.

If we define the upload field 'myfile' without the uploadfolder attribute, 
then the file is deleted properly from the general 'uploads' directory.


-- 

--- 
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/groups/opt_out.


Reply via email to