Example #1
0
    def factory(location, register):
        image = Image()
        image.filename = original.filename
        image.mimeType = original.mimeType

        def afterCopy(translate):
            image.data = original.data

        register(afterCopy)
        return image
Example #2
0
    def set(self, object, value, _getattr=getattr, _setattr=setattr):
        if self.readonly:
            raise TypeError("Can't set values on read-only fields "
                            "(name=%s, class=%s.%s)"
                            % (self.__name__,
                               object.__class__.__module__,
                               object.__class__.__name__))

        if IImage.providedBy(value):
            _setattr(object, self.__name__, value)
        elif IFileData.providedBy(value):
            data = _getattr(object, self.__name__, None)
            if not IImage.providedBy(data):
                data = Image()
                data.data = value.data
                data.mimeType = value.mimeType
                data.filename = value.filename
                _setattr(object, self.__name__, data)
            else:
                data = removeSecurityProxy(data)
                data.data = value.data
                data.mimeType = value.mimeType
                data.filename = value.filename
                _setattr(object, self.__name__, data)

            if self.scale and (self.maxWidth < data.width or
               self.maxHeight < data.height):
                data.scale(self.maxWidth, self.maxHeight)

        elif IFileDataClear.providedBy(value):
            data = _getattr(object, self.__name__, None)
            if IImage.providedBy(data):
                data.clear()
            else:
                _setattr(object, self.__name__, Image())
        elif IFileDataNoValue.providedBy(value):
            pass
        else:
            self.set(object, FileData(value), _getattr, _setattr)