Пример #1
0
    def validate(self, value):
        if not isinstance(value, unicode):
            if not IRichTextData.providedBy(value):
                raise WrongType(value, IRichTextData)

            if self.required:
                if not value.text:
                    raise RequiredMissing()

        return super(RichText, self).validate(value)
Пример #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 IRichTextData.providedBy(value):
            _setattr(object, self.__name__, value)
        else:
            _setattr(object, self.__name__, RichTextData(unicode(value)))

        event.notify(RichTextDataModified(
                object, _getattr(object, self.__name__)))
Пример #3
0
    def get(self, object, _getattr=getattr, _setattr=setattr):
        value = _getattr(object, self.__name__, None)

        if IRichTextData.providedBy(value):
            return value
        elif value is None:
            return None
        elif isinstance(value, list):
            self.set(
                object, RichTextData(value[0], value[1]), _getattr, _setattr)
        else:
            self.set(
                object,
                RichTextData(value, self.default_format), _getattr, _setattr)

        return self.get(object, _getattr, _setattr)
Пример #4
0
    def query(self, default=interfaces.NOVALUE):
        if interfaces.IContextAware.providedBy(self.context) and \
                not self.context.ignoreContext:
            manager = component.queryMultiAdapter(
                (self.context.context, self.context.field),
                interfaces.IDataManager)
            if manager is not None:
                value = manager.query(self.context.field.default_format)
            else:
                self.context.field.default_format
        else:
            value = self.context.value

        if IRichTextData.providedBy(value):
            return value.format
        else:
            return self.context.field.default_format
Пример #5
0
    def get(self):
        if interfaces.IContextAware.providedBy(self.context) and \
                not self.context.ignoreContext:
            manager = component.queryMultiAdapter(
                (self.context.context, self.context.field),
                interfaces.IDataManager)
            if manager is not None:
                try:
                    value = manager.get()
                except TypeError:
                    value = self.context.field.default_format
            else:
                self.context.field.default_format
        else:
            value = self.context.value

        if IRichTextData.providedBy(value):
            return value.format
        else:
            return self.context.field.default_format
Пример #6
0
 def getValue(self):
     if IRichTextData.providedBy(self.value):
         return removeAllProxies(self.value).text
     else:
         return u''
Пример #7
0
 def getValue(self):
     if IRichTextData.providedBy(self.value):
         return self.value.text
     else:
         return self.value
Пример #8
0
    def __eq__(self, other):
        if IRichTextData.providedBy(other):
            if (self.format == other.format) and (self.text == other.text):
                return True

        return False