예제 #1
0
    def before_manage_edit(self, dict):
        "This is the object specific edit stuff"
        if dict.pop('_del',None) == 'Y':
            self.clear()

        if dict.get('data', None):  #don't process if data does not have anything in it
            filename, remove_after = utility.createTempFile(dict['data'])
            content_type = magicfile.magic(filename)
            if content_type.startswith('image'):
                if not self.data:
                    self.manage_addProduct['Image'].manage_addImage('data', '', 'data')
                if self.getConfig('resizeOnUpload'):
                    self.resizeImage(filename)
                elif self.getConfig('resaveOnUpload'):
                    temp_file,x,y = utility.resaveExistingImage(filename)
                    if temp_file is not None:
                        self.data.manage_upload(temp_file)
                        temp_file.close()
                        self.data.width = x
                        self.data.height = y
                    else:
                        self.data.manage_upload(open(filename, 'rb'))
                else:
                    self.data.manage_upload(open(filename, 'rb'))
                self.updateParentPaths(set(['data']))

                self.makeThumbnail(filename)
                self.setFileSize()
                self.storeContentType(content_type) 
            utility.removeTempFile(filename, remove_after)
        try:
            del dict['data']
        except KeyError:
            pass
예제 #2
0
 def resaveExistingImage(self):
     "reisze existing images"
     if self.exists():
         filename, remove_after = utility.createTempFile(self.image.data)
         content_type = magicfile.magic(filename)
         if content_type.startswith('image'):
             temp_file, x, y = utility.resaveExistingImage(filename)
             beforeSize = utility.fileSizeToInt(self.getFileSize())
             if temp_file is not None and os.stat(temp_file.name)[stat.ST_SIZE] < beforeSize:
                 self.image.manage_upload(temp_file)
                 self.image.width = x
                 self.image.height = y
                 #have to redo the content_type after we modify the image in case it has changed
                 content_type = magicfile.magic(temp_file.name)
                 temp_file.close()
                 self.setFileSize()
                 self.image.content_type = content_type
         utility.removeTempFile(filename, remove_after)
예제 #3
0
 def resaveExistingImage(self):
     "reisze existing images"
     if self.exists():
         filename, remove_after = utility.createTempFile(self.image.data)
         content_type = magicfile.magic(filename)
         if content_type.startswith('image'):
             temp_file, x, y = utility.resaveExistingImage(filename)
             beforeSize = utility.fileSizeToInt(self.getFileSize())
             if temp_file is not None and os.stat(
                     temp_file.name)[stat.ST_SIZE] < beforeSize:
                 self.image.manage_upload(temp_file)
                 self.image.width = x
                 self.image.height = y
                 #have to redo the content_type after we modify the image in case it has changed
                 content_type = magicfile.magic(temp_file.name)
                 temp_file.close()
                 self.setFileSize()
                 self.image.content_type = content_type
         utility.removeTempFile(filename, remove_after)
예제 #4
0
 def resaveExistingImage(self):
     "reisze existing images"
     if self.exists():
         filename, remove_after = utility.createTempFile(self.data.data)
         content_type = magicfile.magic(filename)
         if content_type.startswith('image'):
             if self.getConfig('resaveOnUpload'):
                 temp_file,x,y = utility.resaveExistingImage(filename)
                 beforeSize = utility.fileSizeToInt(self.getFileSize())
                 if temp_file is not None and os.stat(temp_file.name)[stat.ST_SIZE] < beforeSize:
                     if not self.data:
                         self.manage_addProduct['Image'].manage_addImage('data', temp_file, 'data')
                     else:
                         self.data.manage_upload(temp_file)
                     self.data.width = x
                     self.data.height = y
                     #have to redo the content_type after we modify the image in case it has changed
                     content_type = magicfile.magic(temp_file.name)
                     temp_file.close()
                     self.setFileSize()
                     self.storeContentType(content_type)
         utility.removeTempFile(filename, remove_after)
예제 #5
0
 def resaveExistingImage(self):
     "reisze existing images"
     if self.exists():
         filename, remove_after = utility.createTempFile(self.data.data)
         content_type = magicfile.magic(filename)
         if content_type.startswith('image'):
             if self.getConfig('resaveOnUpload'):
                 temp_file, x, y = utility.resaveExistingImage(filename)
                 beforeSize = utility.fileSizeToInt(self.getFileSize())
                 if temp_file is not None and os.stat(
                         temp_file.name)[stat.ST_SIZE] < beforeSize:
                     if not self.data:
                         self.manage_addProduct['Image'].manage_addImage(
                             'data', temp_file, 'data')
                     else:
                         self.data.manage_upload(temp_file)
                     self.data.width = x
                     self.data.height = y
                     #have to redo the content_type after we modify the image in case it has changed
                     content_type = magicfile.magic(temp_file.name)
                     temp_file.close()
                     self.setFileSize()
                     self.storeContentType(content_type)
         utility.removeTempFile(filename, remove_after)
예제 #6
0
    def before_manage_edit(self, dict):
        "This is the object specific edit stuff"
        if dict.pop('_del', None) == 'Y':
            self.clear()

        if dict.get('data',
                    None):  #don't process if data does not have anything in it
            filename, remove_after = utility.createTempFile(dict['data'])
            content_type = magicfile.magic(filename)
            if content_type.startswith('image'):
                if not self.data:
                    self.manage_addProduct['Image'].manage_addImage(
                        'data', '', 'data')
                if self.getConfig('resizeOnUpload'):
                    self.resizeImage(filename)
                elif self.getConfig('resaveOnUpload'):
                    temp_file, x, y = utility.resaveExistingImage(filename)
                    if temp_file is not None:
                        self.data.manage_upload(temp_file)
                        temp_file.close()
                        self.data.width = x
                        self.data.height = y
                    else:
                        self.data.manage_upload(open(filename, 'rb'))
                else:
                    self.data.manage_upload(open(filename, 'rb'))
                self.updateParentPaths(set(['data']))

                self.makeThumbnail(filename)
                self.setFileSize()
                self.storeContentType(content_type)
            utility.removeTempFile(filename, remove_after)
        try:
            del dict['data']
        except KeyError:
            pass