add file to zope filesystem unless it exists
I want to have a user upload a file to the zope filesystem, but if the file already exists I want to ignore the request I have a Python Script ## Script (Python) "add_to_filesystem_py" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=folder_name,file_name ##title= ## REQUEST = container.REQUEST RESPONSE = REQUEST.RESPONSE idFolder = getattr(context.Patients, REQUEST.get('id')) folder = getattr(idFolder, folder_name) if not hasattr(folder, file_name): folder.manage_addFile(id='', file=file_name) return getattr(file_name, 'filename') Without the 'if not hasattr(folder, file_name):' the script works fine and adds the file to the filesystem and returns an error if the file already exists there. Apparently I am not using the hasattr part correctly. What is the correct way in a python script to test for the existence of a file in a folder object? Thanks, John Hunter
"John" == John Hunter <jdhunter@ace.bsd.uchicago.edu> writes:
John> I want to have a user upload a file to the zope filesystem, John> but if the file already exists I want to ignore the request [snip] John> Without the 'if not hasattr(folder, file_name):' the script John> works fine and adds the file to the filesystem and returns John> an error if the file already exists there. Apparently I am John> not using the hasattr part correctly. What is the correct John> way in a python script to test for the existence of a file John> in a folder object? Use if file_name in folder.objectIds():
participants (1)
-
John Hunter