def uploadZip(self, file='', REQUEST=None): """ Expand a zipfile into a number of Photos. Go through the zipfile and for each file create a I{Naaya Photo} object. """ err = '' try: if type(file) is not type('') and hasattr(file, 'filename'): # According to the zipfile.py ZipFile just needs a file-like object zf = ZZipFile(file) for name in zf.namelist(): zf.setcurrentfile(name) content = zf.read() if self.isValidImage(content): id = name[max(rfind(name, '/'), rfind(name, '\\'), rfind(name, ':')) + 1:] ob = self._getOb(id, None) if ob: id = '%s_%s' % (PREFIX_NYPHOTO + self.utGenRandomId(6), id) self.addNyPhoto(id=id, title=name, file=content, lang=self.gl_get_selected_language()) else: err = 'Invalid zip file.' except Exception, error: err = str(error)
def uploadZip(self, file='', REQUEST=None, **kwargs): """ Expand a zipfile into a number of Photos. Go through the zipfile and for each file create a I{Naaya Photo} object. """ if REQUEST is not None: schema_raw_data = dict(REQUEST.form) else: schema_raw_data = kwargs err = '' title = None if 'title' in schema_raw_data.keys(): title = schema_raw_data.get('title') del schema_raw_data['title'] try: if type(file) is not type('') and hasattr(file, 'filename'): # According to the zipfile.py ZipFile just needs a file-like object zf = ZZipFile(file) for name in zf.namelist(): zf.setcurrentfile(name) content = zf.read() if self.isValidImage(content): id = name[max(rfind(name, '/'), rfind(name, '\\'), rfind(name, ':')) + 1:] if title: photo_title = title else: photo_title = name self._add_photo(id=id, title=photo_title, file=content, lang=self.gl_get_selected_language(), **schema_raw_data) else: err = 'Invalid zip file.' except Exception, error: err = str(error)