from StringIO import StringIO from OFS.Folder import Folder from AccessControl import getSecurityManager from utils import generateString from TempFile import TempFile class TempFileManager(Folder): """ temporary file manager """ id = 'tempfiles' def __init__(self): Folder.__init__(self) def addFile(self, req): f = req.get('new_file') fname = f.filename fname = fname.split('/')[-1] fname = fname.split('\\')[-1] fname = unicode(fname, 'utf-8') uname = str(getSecurityManager().getUser()) id = generateString(15) tf = TempFile(id, uname) tf.setData(f.read()) tf.setFilename(fname) self._setObject(tf.id, tf) def getFilesByUser(self, uname): return [ x for x in self.objectValues() if x.getUser() == uname ] def deleteFile(self, fid, uname): # check who is deleting whos file? f = getattr(self, fid) if f.getUser() == uname: self._delObject(fid) # raise some error