Hi!!
I have 3 computed fields that call a "resize_image" function to make 3
versions of a uploaded image.
The definition of one of these fields:
Field('foto_portada_detalle', 'upload',
uploadfolder=request.folder+'static/uploads/actividades',
compute=lambda r: resize_image(r['foto_portada'], (200,200), 'detalle',
'actividades'),
autodelete=True,
readable=False)
When I delete the record, all is ok and the images are deleted but when I
update the record with another image one good thing occur: all the other 3
versions get updated BUT one bad thing occur too: the old images stay on
the disk although "autodelete=True"
I think that the resize_image function need to manage the delete of old
images but I don't know how. can you help me? Thank a lot!
The function:
def resize_image(image, size, path, folder, rotate=0):
import os.path
from PIL import Image, ImageOps
if image:
try:
img = Image.open('%sstatic/uploads/%s/%s' % (request.folder,
folder, image))
img = img.convert("RGB")
img = ImageOps.fit(img, size, Image.ANTIALIAS, centering=(0.5,
0.5))
#img.resize(size, Image.ANTIALIAS)
img = img.rotate(rotate)
root, ext = os.path.splitext(image)
filename = '%s_%s%s' %(root, path, ext)
img.save('%sstatic/uploads/%s/%s' % (request.folder, folder,
filename))
return filename
except Exception, e:
return e
else:
return None