Example #1
0
 def __call__(self):
     if self._renderedValueSet():
         value = self._data
     else:
         value = self.context.default
     if value == self.context.missing_value:
         return ""
     return escape(toUnicode(value))
Example #2
0
 def __call__(self):
     if self._renderedValueSet():
         value = self._data
     else:
         value = self.context.default
     if value == self.context.missing_value:
         return ""
     return escape(toUnicode(value))
Example #3
0
 def _toFieldValue(self, value):
     value = super(TextAreaWidget, self)._toFieldValue(value)
     if value:
         try:
             value = toUnicode(value)
         except ValueError as v:
             raise ConversionError(_("Invalid unicode data"), v)
         else:
             value = value.replace("\r\n", "\n")
     return value
Example #4
0
 def _toFieldValue(self, value):
     value = super(TextAreaWidget, self)._toFieldValue(value)
     if value:
         try:
             value = toUnicode(value)
         except ValueError as v:
             raise ConversionError(_("Invalid unicode data"), v)
         else:
             value = value.replace("\r\n", "\n")
     return value
Example #5
0
 def _toFieldValue(self, input):
     if self.convert_missing_value and input == self._missing:
         value = self.context.missing_value
     else:
         # We convert everything to unicode. This might seem a bit crude,
         # but anything contained in a TextWidget should be representable
         # as a string. Note that you always have the choice of overriding
         # the method.
         try:
             value = toUnicode(input)
         except ValueError as v:
             raise ConversionError(_("Invalid text data"), v)
     return value
Example #6
0
 def _toFieldValue(self, input):
     if self.convert_missing_value and input == self._missing:
         value = self.context.missing_value
     else:
         # We convert everything to unicode. This might seem a bit crude,
         # but anything contained in a TextWidget should be representable
         # as a string. Note that you always have the choice of overriding
         # the method.
         try:
             value = toUnicode(input)
         except ValueError as v:
             raise ConversionError(_("Invalid text data"), v)
     return value
Example #7
0
def renderTag(tag, **kw):
    """Render the tag. Well, not all of it, as we may want to / it."""
    attr_list = []

    # special case handling for cssClass
    cssClass = kw.pop('cssClass', u'')

    # If the 'type' attribute is given, append this plus 'Type' as a
    # css class. This allows us to do subselector stuff in css without
    # necessarily having a browser that supports css subselectors.
    # This is important if you want to style radio inputs differently than
    # text inputs.
    cssWidgetType = kw.get('type', u'')
    if cssWidgetType:
        cssWidgetType += u'Type'
    names = [c for c in (cssClass, cssWidgetType) if c]
    if names:
        attr_list.append(u'class="%s"' % u' '.join(names))

    style = kw.pop('style', u'')
    if style:
        attr_list.append(u'style=%s' % quoteattr(style))

    # special case handling for extra 'raw' code
    if 'extra' in kw:
        # could be empty string but we don't care
        extra = u" " + kw.pop('extra')
    else:
        extra = u''

    # handle other attributes
    if kw:
        items = sorted(kw.items())
        for key, value in items:
            if value is None:
                warnings.warn(
                    "None was passed for attribute %r.  Passing None "
                    "as attribute values to renderTag is deprecated. "
                    "Passing None as an attribute value will be disallowed "
                    "starting in Zope 3.3."
                    % key,
                    DeprecationWarning, stacklevel=2)
                value = key
            attr_list.append(u'%s=%s' % (key, quoteattr(toUnicode(value))))

    if attr_list:
        attr_str = u" ".join(attr_list)
        return u"<%s %s%s" % (tag, attr_str, extra)
    else:
        return u"<%s%s" % (tag, extra)
Example #8
0
def renderTag(tag, **kw):
    """Render the tag. Well, not all of it, as we may want to / it."""
    attr_list = []

    # special case handling for cssClass
    cssClass = kw.pop('cssClass', u'')

    # If the 'type' attribute is given, append this plus 'Type' as a
    # css class. This allows us to do subselector stuff in css without
    # necessarily having a browser that supports css subselectors.
    # This is important if you want to style radio inputs differently than
    # text inputs.
    cssWidgetType = kw.get('type', u'')
    if cssWidgetType:
        cssWidgetType += u'Type'
    names = [c for c in (cssClass, cssWidgetType) if c]
    if names:
        attr_list.append(u'class="%s"' % u' '.join(names))

    style = kw.pop('style', u'')
    if style:
        attr_list.append(u'style=%s' % quoteattr(style))

    # special case handling for extra 'raw' code
    if 'extra' in kw:
        # could be empty string but we don't care
        extra = u" " + kw.pop('extra')
    else:
        extra = u''

    # handle other attributes
    if kw:
        items = sorted(kw.items())
        for key, value in items:
            if value is None:
                warnings.warn(
                    "None was passed for attribute %r.  Passing None "
                    "as attribute values to renderTag is deprecated. "
                    "Passing None as an attribute value will be disallowed "
                    "starting in Zope 3.3." % key,
                    DeprecationWarning,
                    stacklevel=2)
                value = key
            attr_list.append(u'%s=%s' % (key, quoteattr(toUnicode(value))))

    if attr_list:
        attr_str = u" ".join(attr_list)
        return u"<%s %s%s" % (tag, attr_str, extra)
    else:
        return u"<%s%s" % (tag, extra)
Example #9
0
 def _toFormValue(self, value):
     if value == self.context.missing_value:
         value = self._missing
     else:
         return toUnicode(value)
Example #10
0
 def _toFormValue(self, value):
     if value == self.context.missing_value:
         value = self._missing
     else:
         return toUnicode(value)