[Checkins] SVN: z3c.form/trunk/src/z3c/form/ fix a bug where file
upload converter return unicode instead of ascii for a bytes field,
and added a special data converter for the testing file upload
widget.
Paul Carduner
paulcarduner at gmail.com
Mon May 19 13:46:14 EDT 2008
Log message for revision 86844:
fix a bug where file upload converter return unicode instead of ascii for a bytes field, and added a special data converter for the testing file upload widget.
Changed:
U z3c.form/trunk/src/z3c/form/browser/file-testing.txt
U z3c.form/trunk/src/z3c/form/configure.zcml
U z3c.form/trunk/src/z3c/form/converter.py
U z3c.form/trunk/src/z3c/form/converter.txt
A z3c.form/trunk/src/z3c/form/file.zcml
A z3c.form/trunk/src/z3c/form/file_testing.zcml
U z3c.form/trunk/src/z3c/form/testing.py
-=-
Modified: z3c.form/trunk/src/z3c/form/browser/file-testing.txt
===================================================================
--- z3c.form/trunk/src/z3c/form/browser/file-testing.txt 2008-05-19 17:42:00 UTC (rev 86843)
+++ z3c.form/trunk/src/z3c/form/browser/file-testing.txt 2008-05-19 17:46:13 UTC (rev 86844)
@@ -111,4 +111,4 @@
>>> conv
<TestingFileUploadDataConverter converts from Bytes to FileWidget>
>>> conv.toFieldValue("")
- u'File upload contents.'
+ 'File upload contents.'
Modified: z3c.form/trunk/src/z3c/form/configure.zcml
===================================================================
--- z3c.form/trunk/src/z3c/form/configure.zcml 2008-05-19 17:42:00 UTC (rev 86843)
+++ z3c.form/trunk/src/z3c/form/configure.zcml 2008-05-19 17:46:13 UTC (rev 86844)
@@ -54,10 +54,8 @@
<adapter
factory=".converter.TimedeltaDataConverter"
/>
+ <include file="file.zcml" />
<adapter
- factory=".converter.FileUploadDataConverter"
- />
- <adapter
factory=".converter.SequenceDataConverter"
/>
<adapter
Modified: z3c.form/trunk/src/z3c/form/converter.py
===================================================================
--- z3c.form/trunk/src/z3c/form/converter.py 2008-05-19 17:42:00 UTC (rev 86843)
+++ z3c.form/trunk/src/z3c/form/converter.py 2008-05-19 17:46:13 UTC (rev 86844)
@@ -238,7 +238,7 @@
else:
return self.field.missing_value
else:
- return unicode(value)
+ return str(value)
class SequenceDataConverter(BaseDataConverter):
Modified: z3c.form/trunk/src/z3c/form/converter.txt
===================================================================
--- z3c.form/trunk/src/z3c/form/converter.txt 2008-05-19 17:42:00 UTC (rev 86843)
+++ z3c.form/trunk/src/z3c/form/converter.txt 2008-05-19 17:46:13 UTC (rev 86844)
@@ -400,7 +400,7 @@
>>> simple = 'foobar'
>>> fudc.toFieldValue(simple)
- u'foobar'
+ 'foobar'
The converter can also convert FileUpload objects. Setup a fields storage
stub...
Added: z3c.form/trunk/src/z3c/form/file.zcml
===================================================================
--- z3c.form/trunk/src/z3c/form/file.zcml (rev 0)
+++ z3c.form/trunk/src/z3c/form/file.zcml 2008-05-19 17:46:13 UTC (rev 86844)
@@ -0,0 +1,18 @@
+<configure
+ xmlns="http://namespaces.zope.org/zope"
+ i18n_domain="z3c.form">
+
+ <!-- This data converter is registered in its own file so that it
+ can be easily excluded in other packages. For example, we may
+ want to use the testing.py's file upload data converter widget
+ instead of the standard one when we test our application. By
+ placing this registration in its own file, we do not have to do
+ zcml overrides, but can rather just exclude this file and
+ include file_testing.zcml-->
+
+ <!-- Data Converters -->
+ <adapter
+ factory=".converter.FileUploadDataConverter"
+ />
+
+</configure>
Added: z3c.form/trunk/src/z3c/form/file_testing.zcml
===================================================================
--- z3c.form/trunk/src/z3c/form/file_testing.zcml (rev 0)
+++ z3c.form/trunk/src/z3c/form/file_testing.zcml 2008-05-19 17:46:13 UTC (rev 86844)
@@ -0,0 +1,10 @@
+<configure
+ xmlns="http://namespaces.zope.org/zope"
+ i18n_domain="z3c.form">
+
+ <!-- Data Converters -->
+ <adapter
+ factory=".testing.TestingFileUploadDataConverter"
+ />
+
+</configure>
Modified: z3c.form/trunk/src/z3c/form/testing.py
===================================================================
--- z3c.form/trunk/src/z3c/form/testing.py 2008-05-19 17:42:00 UTC (rev 86843)
+++ z3c.form/trunk/src/z3c/form/testing.py 2008-05-19 17:46:13 UTC (rev 86844)
@@ -32,6 +32,17 @@
from z3c.form.browser import radio, select, text
+class TestingFileUploadDataConverter(converter.FileUploadDataConverter):
+ """A special file upload data converter that works with testing."""
+ zope.component.adapts(
+ zope.schema.interfaces.IBytes, interfaces.IFileWidget)
+
+ def toFieldValue(self, value):
+ if value is None or value == '':
+ value = self.widget.request.get(self.widget.name+'.testing', '')
+ return super(TestingFileUploadDataConverter, self).toFieldValue(value)
+
+
class TestRequest(TestRequest):
zope.interface.implements(interfaces.IFormLayer)
More information about the Checkins
mailing list