[Zope3-checkins] SVN: Zope3/trunk/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:45:59 EDT 2004


Log message for revision 27063:
  make the special Rotterdam skin widget deals with line-end normalization
  (closes issue #259)
  


Changed:
  U   Zope3/trunk/src/zope/app/rotterdam/editingwidgets.py
  A   Zope3/trunk/src/zope/app/rotterdam/tests/test_editingwidgets.py
  U   Zope3/trunk/src/zope/pagetemplate/pagetemplate.py


-=-
Modified: Zope3/trunk/src/zope/app/rotterdam/editingwidgets.py
===================================================================
--- Zope3/trunk/src/zope/app/rotterdam/editingwidgets.py	2004-08-12 16:43:14 UTC (rev 27062)
+++ Zope3/trunk/src/zope/app/rotterdam/editingwidgets.py	2004-08-12 16:45:58 UTC (rev 27063)
@@ -22,8 +22,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 = ""
@@ -37,7 +103,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",
@@ -53,4 +119,3 @@
     def contents(self):
         """Make the contents available to the template"""
         return self._getFormData()
-

Added: Zope3/trunk/src/zope/app/rotterdam/tests/test_editingwidgets.py
===================================================================
--- Zope3/trunk/src/zope/app/rotterdam/tests/test_editingwidgets.py	2004-08-12 16:43:14 UTC (rev 27062)
+++ Zope3/trunk/src/zope/app/rotterdam/tests/test_editingwidgets.py	2004-08-12 16:45:58 UTC (rev 27063)
@@ -0,0 +1,21 @@
+##############################################################################
+#
+# Copyright (c) 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Tests for zope.app.rotterdam.editingwidgets.
+
+$Id$
+"""
+from zope.testing.doctest import DocTestSuite
+
+def test_suite():
+    return DocTestSuite("zope.app.rotterdam.editingwidgets")


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

Modified: Zope3/trunk/src/zope/pagetemplate/pagetemplate.py
===================================================================
--- Zope3/trunk/src/zope/pagetemplate/pagetemplate.py	2004-08-12 16:43:14 UTC (rev 27062)
+++ Zope3/trunk/src/zope/pagetemplate/pagetemplate.py	2004-08-12 16:45:58 UTC (rev 27063)
@@ -144,8 +144,6 @@
             errend = text.find('-->')
             if errend >= 0:
                 text = text[errend + 3:]
-                if text[:1] == "\r":
-                    text = text[1:]
                 if text[:1] == "\n":
                     text = text[1:]
         if self._text != text:



More information about the Zope3-Checkins mailing list