[Checkins] SVN: zope.app.form/trunk/src/zope/app/form/browser/te FileWidget tries to be smarter about not deleting the currently stored content when the user did not upload a new file.

Christian Zagrodnick cz at gocept.com
Sat Jun 23 06:38:38 EDT 2007


Log message for revision 76975:
  FileWidget tries to be smarter about not deleting the currently stored content when the user did not upload a new file.

Changed:
  U   zope.app.form/trunk/src/zope/app/form/browser/tests/test_filewidget.py
  U   zope.app.form/trunk/src/zope/app/form/browser/textwidgets.py

-=-
Modified: zope.app.form/trunk/src/zope/app/form/browser/tests/test_filewidget.py
===================================================================
--- zope.app.form/trunk/src/zope/app/form/browser/tests/test_filewidget.py	2007-06-23 10:25:23 UTC (rev 76974)
+++ zope.app.form/trunk/src/zope/app/form/browser/tests/test_filewidget.py	2007-06-23 10:38:37 UTC (rev 76975)
@@ -72,6 +72,14 @@
         self._widget.extra = 'style="color: red"'
         self.verifyResult(self._widget.hidden(), check_list)
 
+    def testToFieldValue(self):
+        widget = self._widget
+        field = widget.context
+        content = field.context
+        field.set(content, 'file content')
+        self.assertEquals('file content', widget._toFieldValue(''))
+        self.assertEquals('new content',
+                          widget._toFieldValue(StringIO('new content')))
 
 
 def test_suite():

Modified: zope.app.form/trunk/src/zope/app/form/browser/textwidgets.py
===================================================================
--- zope.app.form/trunk/src/zope/app/form/browser/textwidgets.py	2007-06-23 10:25:23 UTC (rev 76974)
+++ zope.app.form/trunk/src/zope/app/form/browser/textwidgets.py	2007-06-23 10:38:37 UTC (rev 76975)
@@ -475,6 +475,11 @@
 
     def _toFieldValue(self, input):
         if input is None or input == '':
+            # There was no input. With File-Upload this usually means that the
+            # value should *not* change. Let's try to get the old value.
+            content = self.context.context
+            if self.context.interface.providedBy(content):
+                return self.context.get(content)
             return self.context.missing_value
         try:
             seek = input.seek



More information about the Checkins mailing list