[Zope3-checkins] SVN: Zope3/branches/ZopeX3-3.0/src/zope/ make the special Rotterdam skin widget deals with line-end normalization

Fred L. Drake, Jr. fdrake at gmail.com
Thu Aug 12 12:52:04 EDT 2004


Log message for revision 27066:
  make the special Rotterdam skin widget deals with line-end normalization
  (closes issue #259; merged from Zope 3 trunk revision 27063)
  


Changed:
  U   Zope3/branches/ZopeX3-3.0/src/zope/app/rotterdam/editingwidgets.py
  A   Zope3/branches/ZopeX3-3.0/src/zope/app/rotterdam/tests/test_editingwidgets.py
  U   Zope3/branches/ZopeX3-3.0/src/zope/pagetemplate/pagetemplate.py


-=-
Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/rotterdam/editingwidgets.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/rotterdam/editingwidgets.py	2004-08-12 16:50:35 UTC (rev 27065)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/rotterdam/editingwidgets.py	2004-08-12 16:52:03 UTC (rev 27066)
@@ -23,8 +23,74 @@
 from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
 
 class SimpleEditingWidget(TextAreaWidget):
-    """Improved textarea editing, with async saving using JavaScript."""
+    """Improved textarea editing, with async saving using JavaScript.
 
+
+    Multi-line text (unicode) input.
+
+    >>> from zope.publisher.browser import TestRequest
+    >>> from zope.schema import Text
+    >>> field = Text(__name__='foo', title=u'on')
+    >>> request = TestRequest(form={'field.foo': u'Hello\\r\\nworld!'})
+    >>> widget = SimpleEditingWidget(field, request)
+    >>> widget.style = ''
+    >>> widget.hasInput()
+    True
+    >>> widget.getInputValue()
+    u'Hello\\nworld!'
+
+    >>> def normalize(s):
+    ...   return '\\n  '.join(filter(None, s.split(' ')))
+
+    >>> print normalize( widget() )
+    <textarea
+      cols="60"
+      id="field.foo"
+      name="field.foo"
+      rows="15"
+      >Hello\r
+    world!</textarea>
+
+    >>> print normalize( widget.hidden() )
+    <input
+      class="hiddenType"
+      id="field.foo"
+      name="field.foo"
+      type="hidden"
+      value="Hello\r
+    world!"
+      />
+
+    Calling `setRenderedValue` will change what gets output:
+
+    >>> widget.setRenderedValue("Hey\\ndude!")
+    >>> print normalize( widget() )
+    <textarea
+      cols="60"
+      id="field.foo"
+      name="field.foo"
+      rows="15"
+      >Hey\r
+    dude!</textarea>
+
+    Check that HTML is correctly encoded and decoded:
+
+    >>> request = TestRequest(
+    ...     form={'field.foo': u'&lt;h1&gt;&amp;copy;&lt;/h1&gt;'})
+    >>> widget = SimpleEditingWidget(field, request)
+    >>> widget.style = ''
+    >>> widget.getInputValue()
+    u'<h1>&copy;</h1>'
+
+    >>> print normalize( widget() )
+    <textarea
+      cols="60"
+      id="field.foo"
+      name="field.foo"
+      rows="15"
+      >&lt;h1&gt;&amp;copy;&lt;/h1&gt;</textarea>
+    """
+
     implements(IInputWidget)
 
     default = ""
@@ -38,7 +104,7 @@
     def _toFieldValue(self, value):
         if self.context.min_length and not value:
             return None
-        return value
+        return super(SimpleEditingWidget, self)._toFieldValue(value)
 
     def __call__(self):
         return renderElement("textarea",
@@ -54,4 +120,3 @@
     def contents(self):
         """Make the contents available to the template"""
         return self._getFormData()
-

Copied: Zope3/branches/ZopeX3-3.0/src/zope/app/rotterdam/tests/test_editingwidgets.py (from rev 27063, Zope3/trunk/src/zope/app/rotterdam/tests/test_editingwidgets.py)


Property changes on: Zope3/branches/ZopeX3-3.0/src/zope/app/rotterdam/tests/test_editingwidgets.py
___________________________________________________________________
Name: svn:mime-type
   + text/x-python
Name: svn:eol-style
   + native

Modified: Zope3/branches/ZopeX3-3.0/src/zope/pagetemplate/pagetemplate.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/pagetemplate/pagetemplate.py	2004-08-12 16:50:35 UTC (rev 27065)
+++ Zope3/branches/ZopeX3-3.0/src/zope/pagetemplate/pagetemplate.py	2004-08-12 16:52:03 UTC (rev 27066)
@@ -143,7 +143,9 @@
         if text.startswith(_error_start):
             errend = text.find('-->')
             if errend >= 0:
-                text = text[errend + 4:]
+                text = text[errend + 3:]
+                if text[:1] == "\n":
+                    text = text[1:]
         if self._text != text:
             self._text = text
 



More information about the Zope3-Checkins mailing list