def _delete_media(self, media): # FIXME: Ensure that if the first file is deleted from the file system, # then the second fails, the first file is deleted from the # file system and not linking to a nonexistent file. # Delete every file from the storage engine for file in media.files: file.storage.delete(file.unique_id) # Remove this item from the DBSession so that the foreign key # ON DELETE CASCADE can take effect. DBSession.expunge(file) # Delete the media DBSession.delete(media) DBSession.flush() # Cleanup the thumbnails delete_thumbs(media)