Hello,

I am generating thumbnails with Bruno's slice : 
http://www.web2pyslices.com/slice/show/1522/generate-a-thumbnail-that-fits-in-a-box

But I use "uploadseparate=True" so when I update image the derived 
thumbnails are let behind in the precedent folder, but the original image 
the one inputed by the user that serve for generating the thumbnails is 
cleared out by Field method "delete_uploaded_files()" that is call on 
update in a callback _before_update, I guess to allow the line 10045 of dal 
: "oldname = record.get(fieldname, None)" get the precedent file name 
before it get updated. I guess I need to  do the same, because I don't see 
other way to get the old file name other way... 

Here model :

db.define_table('auth_user', ...
    Field('image','upload', uploadseparate=True, label=T('Profile image'), 
autodelete=True),
    Field('address_book_image','upload',uploadseparate=True, compute=lambda 
row: SMARTHUMB(row.image, (75,75), name='address_book_thumb'), 
autodelete=True),
    Field('profile_image','upload',uploadseparate=True, compute=lambda row: 
SMARTHUMB(row.image, (160,160), name='profile_thumb'), autodelete=True))

So, what I thought is to do that :

# Controller

def delete_thumb():
    row = db(db.auth_user.id == request.args(1)).select()
    oldfoldername  = 
db.auth_user[fieldname].retrieve_file_properties(row['picture'])['path']
    oldfilename = 
db.auth_user[fieldname].retrieve_file_properties(row['picture'])['filename']
    oldpath = pjoin(oldfoldername, oldfilename)
    if exists(oldpath):
        os.unlink(oldpath)

def controller_func():
    db.auth_user._before_update.append(Set.delete_thumb())
    db.auth_user._before_delete = [Set.delete_thumb()]
    form = SQLFORM(db.auth_user, request.args(1), ...)
    if form.process().accepted:
        response.flash = T('Profile updated')
        redirect(URL(c='directory',f='file',args=(auth.user_id)))
    elif form.errors:
        response.flash = T('There is error')
    else:
        response.flash = T('Fill or update the form')


NOT TESTED

Thanks for your help.

Richard

-- 

--- 
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