web2py / pydal

A pure Python Database Abstraction Layer
BSD 3-Clause "New" or "Revised" License
497 stars 139 forks source link

_before_* callbacks ignores file deletion #320

Open niphlod opened 8 years ago

niphlod commented 8 years ago

When the model has defined autodelete=True, and the callback retirns True the register in the dal will not be deleted, but the files in uploads/ desapears.

Model

# -*- coding: utf-8 -*-

def pprint(*args): print args
def bkp_delete( s ):
#    pprint(s) #.select()[0]
    return True    

db.define_table('img',
    Field('image',
        'upload',
        required=True,
        notnull=True,
        autodelete=True,
        uploadseparate=True),
    Field('mdate', 'datetime', notnull=True),
    Field('landmark', 'boolean'))

db.img._before_delete.append( lambda s: bkp_delete(s) ) 

Controller

# -*- coding: utf-8 -*-

def index(): 
    return dict(message="hello from img.py")

def add():
    form = SQLFORM(db.img).process()
    return dict(f=form)

def grid():
    grid=SQLFORM.grid(db.img, user_signature=False)
    return dict(grid=grid)

# add at least 2 registers
# delete 1
# go to de grid, you will see the 2registers.
# try to see the attachment
niphlod commented 8 years ago

imported from https://github.com/web2py/web2py/issues/1147

BuhtigithuB commented 8 years ago

330 is a possible duplicate of this issue or somewhat related...