[Zope3-checkins] SVN: Zope3/branches/jhauser-filefieldwidget/src/zope/ Moved mime widgets to own file mimewidgets.py, delete fielwidgets.py

Roger Ineichen roger at projekt01.ch
Mon Jan 24 10:14:59 EST 2005


Log message for revision 28921:
  Moved mime widgets to own file mimewidgets.py, delete fielwidgets.py
  Move FileWidget back to textwidgets
  Added test for schema field
  
  NOTE: There is a bug in ftest setup. 
  The method response = self.publish(..., basic='mgr:mgrpw')
  Doesn't give me the permission on subwidgets, but in reality it works.
  
  TODO:
  Add special session supported MimeWidget and make subwidgets 
  read from the session.

Changed:
  U   Zope3/branches/jhauser-filefieldwidget/src/zope/app/file/browser/configure.zcml
  U   Zope3/branches/jhauser-filefieldwidget/src/zope/app/file/browser/file.py
  U   Zope3/branches/jhauser-filefieldwidget/src/zope/app/file/browser/ftests.py
  U   Zope3/branches/jhauser-filefieldwidget/src/zope/app/file/configure.zcml
  U   Zope3/branches/jhauser-filefieldwidget/src/zope/app/file/interfaces.py
  U   Zope3/branches/jhauser-filefieldwidget/src/zope/app/form/browser/__init__.py
  U   Zope3/branches/jhauser-filefieldwidget/src/zope/app/form/browser/configure.zcml
  D   Zope3/branches/jhauser-filefieldwidget/src/zope/app/form/browser/filewidgets.py
  A   Zope3/branches/jhauser-filefieldwidget/src/zope/app/form/browser/ftests/test_schemawidget.py
  A   Zope3/branches/jhauser-filefieldwidget/src/zope/app/form/browser/mimewidgets.py
  U   Zope3/branches/jhauser-filefieldwidget/src/zope/app/form/browser/schemawidget.pt
  U   Zope3/branches/jhauser-filefieldwidget/src/zope/app/form/browser/schemawidgets.py
  U   Zope3/branches/jhauser-filefieldwidget/src/zope/app/form/browser/textwidgets.py
  U   Zope3/branches/jhauser-filefieldwidget/src/zope/schema/__init__.py
  U   Zope3/branches/jhauser-filefieldwidget/src/zope/schema/_field.py
  U   Zope3/branches/jhauser-filefieldwidget/src/zope/schema/interfaces.py

-=-
Modified: Zope3/branches/jhauser-filefieldwidget/src/zope/app/file/browser/configure.zcml
===================================================================
--- Zope3/branches/jhauser-filefieldwidget/src/zope/app/file/browser/configure.zcml	2005-01-24 14:59:47 UTC (rev 28920)
+++ Zope3/branches/jhauser-filefieldwidget/src/zope/app/file/browser/configure.zcml	2005-01-24 15:14:59 UTC (rev 28921)
@@ -15,21 +15,30 @@
 
   <browser:addMenuItem
       class="zope.app.file.interfaces.IFile"
-      title="- File"
+      title="File"
       description="A content type File"
       permission="zope.ManageContent"
-      view="addFile.html"
+      view="zope.app.file.File"
       />
 
   <browser:addform
-      name="addFile.html"
-      label="Add a content type File"
+      name="zope.app.file.File"
+      label="Add a File"
       schema="zope.app.file.interfaces.IFile"
       fields="contents"
       content_factory="zope.app.file.File"
       permission="zope.ManageContent"
       />
 
+  <browser:editform
+      name="fileupload.html"
+      menu="zmi_views" title="Upload"
+      for="zope.app.file.interfaces.IFile"
+      schema="zope.app.file.interfaces.IFile"
+      fields="contents"
+      permission="zope.ManageContent"
+      />
+
   <browser:menuItem
       menu="zmi_views" title="Text Edit"
       for="zope.app.file.interfaces.IFile"
@@ -39,41 +48,54 @@
 
   <browser:editform
       name="fileedit.html"
+      for="zope.app.file.interfaces.IFile"
       schema="zope.app.file.interfaces.IFile"
+      fields="contents"
       label="Change a text file"
       permission="zope.ManageContent" 
       >
 
     <widget
-        field="data"
-        class="zope.app.form.browser.BytesAreaWidget" />
+        field="contents"
+        class="zope.app.form.browser.MimeTextWidget" />
 
   </browser:editform>
 
-  <browser:editform
-      name="fileupload.html"
-      menu="zmi_views" title="Upload"
-      for="zope.app.file.interfaces.IFile"
-      schema="zope.app.file.interfaces.IFile"
-      fields="contents"
-      permission="zope.ManageContent"
-      />
-
   <browser:page
       for="zope.app.file.interfaces.IFile"
       name="index.html"
       permission="zope.View"
-      class=".file.NewStyleFileView"
+      class=".file.FileView"
       attribute="show"
       />
 
+  <browser:icon
+      name="zmi_icon"
+      for="zope.app.file.interfaces.IFile"
+      file="file_icon.gif"
+      />
+
+  <!-- Preview views - requires zope.app.preview -->
+
+  <configure package="zope.app.preview">
+
+    <browser:page
+        for="zope.app.file.interfaces.IFile"
+        name="preview.html"
+        template="preview.pt"
+        permission="zope.ManageContent"
+        menu="zmi_views" title="Preview"
+        />
+
+  </configure>
+
 <!-- BBB: old style files -->
 
   <browser:menuItem
-      menu="zmi_views" title="Edit"
+      menu="zmi_views" title="Edit (BBB)"
       for="zope.app.file.interfaces.IFile"
       action="edit.html"
-      filter="python:context.contentType.startswith('text/')"
+      filter="python:context.contents.mimeType.startswith('text/')"
       permission="zope.ManageContent" />
 
   <browser:editform
@@ -91,58 +113,11 @@
 
   <browser:page
       name="upload.html"
-      menu="zmi_views" title="BBB Upload"
+      menu="zmi_views" title="Upload (BBB)"
       for="zope.app.file.interfaces.IFile"
       template="file_upload.pt"
       class=".file.FileUpload"
       permission="zope.ManageContent"
       />
 
-<!-- add the index.html view back for BBB files
-     TODO: Perhaps we can use menuItem and filter/condition
-  <browser:page
-      for="zope.app.file.interfaces.IFile"
-      name="index.html"
-      permission="zope.View"
-      class=".file.FileView"
-      attribute="show"
-      />
--->
-
-  <browser:addMenuItem
-      class="zope.app.file.File"
-      title="File"
-      description="A File"
-      permission="zope.ManageContent"
-      view="zope.app.file.File"
-      />
-
-  <browser:page
-      name="zope.app.file.File"
-      for="zope.app.container.interfaces.IAdding"
-      template="file_add.pt"
-      class=".file.FileAdd"
-      permission="zope.ManageContent"
-      />
-
-  <browser:icon
-      name="zmi_icon"
-      for="zope.app.file.interfaces.IFile"
-      file="file_icon.gif"
-      />
-
-  <!-- Preview views - requires zope.app.preview -->
-
-  <configure package="zope.app.preview">
-
-    <browser:page
-        for="zope.app.file.interfaces.IFile"
-        name="preview.html"
-        template="preview.pt"
-        permission="zope.ManageContent"
-        menu="zmi_views" title="Preview"
-        />
-
-  </configure>
-
 </configure>

Modified: Zope3/branches/jhauser-filefieldwidget/src/zope/app/file/browser/file.py
===================================================================
--- Zope3/branches/jhauser-filefieldwidget/src/zope/app/file/browser/file.py	2005-01-24 14:59:47 UTC (rev 28920)
+++ Zope3/branches/jhauser-filefieldwidget/src/zope/app/file/browser/file.py	2005-01-24 15:14:59 UTC (rev 28921)
@@ -17,6 +17,7 @@
 """
 
 from datetime import datetime
+from warnings import warn
 
 import zope.event
 
@@ -28,14 +29,14 @@
 __docformat__ = 'restructuredtext'
 
 
-class NewStyleFileView(object):
+class FileView(object):
 
     def show(self):
         """Call the File"""
         request = self.request
         if request is not None:
             request.response.setHeader('Content-Type',
-                                       self.context.contentType)
+                                       self.context.getMimeType())
             request.response.setHeader('Content-Length',
                                        self.context.getSize())
 
@@ -43,30 +44,21 @@
         # access the MimeData via .contents
         # But first we have to support read and write permission in
         # the open method
-        return self.context.contents.open('r').read()
+        return self.context.open().read()
 
 
-class FileView(object):
-
-    def show(self):
-        """Call the File"""
-        request = self.request
-        if request is not None:
-            request.response.setHeader('Content-Type',
-                                       self.context.contentType)
-            request.response.setHeader('Content-Length',
-                                       self.context.getSize())
-
-        return self.context.data
-
-
+# BBB: depricated view, replaced by editform for new style files
 class FileUpdateView(object):
 
     def __init__(self, context, request):
+        warn("The IFile FileUpdateView view is deprecated, use addform directive",
+            DeprecationWarning, 2)
         self.context = context
         self.request = request
 
     def errors(self):
+        warn("The IFile FileUpdateView view is deprecated, use addform directive",
+            DeprecationWarning, 2)
         form = self.request.form
         if "UPDATE_SUBMIT" in form:
             filename = getattr(form["field.data"], "filename", None)
@@ -80,6 +72,8 @@
         return ''
 
 
+
+# BBB: depricated view, replaced by addform for new style files
 class FileAdd(FileUpdateView):
     """View that adds a new File object based on a file upload.
 
@@ -130,7 +124,15 @@
 
     """
 
+    def __init__(self, context, request):
+        warn("The IFile FileAdd view is deprecated, use addform directive",
+            DeprecationWarning, 2)
+        self.context = context
+        self.request = request
+
     def update_object(self, data, contenttype):
+        warn("The IFile FileAdd view is deprecated, use addform directive",
+            DeprecationWarning, 2)
         f = File(data, contenttype)
         zope.event.notify(objectevent.ObjectCreatedEvent(f))
         self.context.add(f)
@@ -138,6 +140,8 @@
         return ''
 
 
+
+# BBB: depricated view, replaced by editform for new style files
 class FileUpload(FileUpdateView):
     """View that updates an existing File object with a new upload.
 
@@ -177,7 +181,15 @@
     'text/plain'
     """
 
+    def __init__(self, context, request):
+        warn("The IFile FileUpload view is deprecated, use addform directive",
+            DeprecationWarning, 2)
+        self.context = context
+        self.request = request
+
     def update_object(self, data, contenttype):
+        warn("The IFile FileUpload view is deprecated, use editform directive",
+            DeprecationWarning, 2)
         self.context.contentType = contenttype
         self.context.data = data
         formatter = self.request.locale.dates.getFormatter(

Modified: Zope3/branches/jhauser-filefieldwidget/src/zope/app/file/browser/ftests.py
===================================================================
--- Zope3/branches/jhauser-filefieldwidget/src/zope/app/file/browser/ftests.py	2005-01-24 14:59:47 UTC (rev 28920)
+++ Zope3/branches/jhauser-filefieldwidget/src/zope/app/file/browser/ftests.py	2005-01-24 15:14:59 UTC (rev 28921)
@@ -50,11 +50,13 @@
         response = self.publish(
             '/+/zope.app.file.File=',
             form={'type_name': u'zope.app.file.File',
-                  'field.data': StringIO('A file'),
-                  'field.contentType': '',
+                  'field.contents.data': StringIO('A file'),
+                  'field.contents.mimeType': u'',
+                  'field.contents.encoding': u'',
                   'add_input_name': u'file',
                   'UPDATE_SUBMIT': u'Add'},
             basic='mgr:mgrpw')
+
         self.assertEqual(response.getStatus(), 302)
         self.assertEqual(response.getHeader('Location'),
                          'http://localhost/@@contents.html')
@@ -66,35 +68,36 @@
     def testEditForm(self):
         self.addFile()
         response = self.publish(
-            '/file/@@edit.html',
+            '/file/fileedit.html',
             basic='mgr:mgrpw')
         self.assertEqual(response.getStatus(), 200)
         body = response.getBody()
-        self.assert_('Change a file' in body)
+        self.assert_('Change a text file' in body)
         self.assert_('Content Type' in body)
         self.assert_('Data' in body)
         self.assert_(escape(self.content) in body)
-        self.checkForBrokenLinks(body, '/file/@@edit.html', 'mgr:mgrpw')
+        self.checkForBrokenLinks(body, '/file/@@fileedit.html', 'mgr:mgrpw')
 
     def testEdit(self):
         self.addFile()
         response = self.publish(
-            '/file/@@edit.html',
-            form={'field.contents.data': u'<h1>A File</h1>',
-                  'field.contents.contentType': u'text/plain',
-                  'field.contents.encoding': u'',
-                  'UPDATE_SUBMIT': u'Edit'},
+            '/file/fileedit.html',
+            form={'field.contents.data': '<h1>A File</h1>',
+                  'field.contents.mimeType': 'text/plain',
+                  'field.contents.encoding': '',
+                  'UPDATE_SUBMIT': u'Change'},
             basic='mgr:mgrpw')
+
         self.assertEqual(response.getStatus(), 200)
         body = response.getBody()
-        self.assert_('Change a file' in body)
+        self.assert_('Change a text file' in body)
         self.assert_('Content Type' in body)
         self.assert_('Data' in body)
         self.assert_(escape(u'<h1>A File</h1>') in body)
         root = self.getRootFolder()
         file = root['file']
         self.assertEqual(file.open('r').read(), '<h1>A File</h1>')
-        self.assertEqual(file.contentType, 'text/plain')
+        self.assertEqual(file.getMimeType(), 'text/plain')
 
     def testUploadForm(self):
         self.addFile()
@@ -107,27 +110,28 @@
         self.assert_('Content Type' in body)
         self.assert_('Data' in body)
         self.failIf(escape(self.content) in body)
-        self.checkForBrokenLinks(body, '/file/@@upload.html', 'mgr:mgrpw')
+        self.checkForBrokenLinks(body, '/file/@@fileupload.html', 'mgr:mgrpw')
 
     def testUpload(self):
         self.addFile()
         response = self.publish(
             '/file/@@fileupload.html',
-            form={'field.contents.data': StringIO('<h1>A file</h1>'),
-                  'field.contents.contentType': u'text/plain',
-                  'field.contents.encoding': u'UTF-8',
-                  'UPDATE_SUBMIT': u'Change'},
-            basic='mgr:mgrpw')
+            basic='mgr:mgrpw',
+            form={'field.contents.data': StringIO('New file'),
+                  'field.contents.mimeType': u'',
+                  'field.contents.encoding': u'',
+                  'add_input_name': u'file',
+                  'UPDATE_SUBMIT': u'Add'})
         self.assertEqual(response.getStatus(), 200)
         body = response.getBody()
         self.assert_('Encoding Type' in body)
         self.assert_('Content Type' in body)
         self.assert_('Data' in body)
-        self.failIf(escape(u'<h1>A File</h1>') in body)
+        self.failIf(escape(u'<h1>New File</h1>') in body)
         root = self.getRootFolder()
         file = root['file']
-        self.assertEqual(file.open('r').read(), '<h1>A file</h1>')
-        self.assertEqual(file.contentType, 'text/plain')
+        self.assertEqual(file.open('r').read(), '<h1>New file</h1>')
+        self.assertEqual(file.getMimeType(), 'text/plain')
         
     def testIndex(self):
         self.addFile()

Modified: Zope3/branches/jhauser-filefieldwidget/src/zope/app/file/configure.zcml
===================================================================
--- Zope3/branches/jhauser-filefieldwidget/src/zope/app/file/configure.zcml	2005-01-24 14:59:47 UTC (rev 28920)
+++ Zope3/branches/jhauser-filefieldwidget/src/zope/app/file/configure.zcml	2005-01-24 15:14:59 UTC (rev 28921)
@@ -22,11 +22,21 @@
 
     <require
         permission="zope.View"
+        interface=".interfaces.IReadMime"
+        />
+
+    <require
+        permission="zope.View"
         interface=".interfaces.IFile"
         />
 
     <require
         permission="zope.ManageContent"
+        interface=".interfaces.IWriteMime"
+        />
+
+    <require
+        permission="zope.ManageContent"
         set_schema=".interfaces.IFile"
         />
 

Modified: Zope3/branches/jhauser-filefieldwidget/src/zope/app/file/interfaces.py
===================================================================
--- Zope3/branches/jhauser-filefieldwidget/src/zope/app/file/interfaces.py	2005-01-24 14:59:47 UTC (rev 28920)
+++ Zope3/branches/jhauser-filefieldwidget/src/zope/app/file/interfaces.py	2005-01-24 15:14:59 UTC (rev 28921)
@@ -18,8 +18,7 @@
 __docformat__ = 'restructuredtext'
 
 from zope.schema import Bytes
-from zope.schema import MimeData, MimeDataEncoding, MimeType
-from zope.schema import Schema
+from zope.schema import Mime, MimeData, MimeDataEncoding, MimeType
 from zope.interface import Interface
 from zope.app.i18n import ZopeMessageIDFactory as _
 
@@ -60,9 +59,6 @@
 class IReadMime(Interface):
     """Mime read interface."""
 
-    def getSize():
-        """Return the byte-size of the data of the object."""
-
     def getMimeType():
         """Return the mime-type of the file."""
 
@@ -120,10 +116,10 @@
 
     # TODO: rember, we remove the contentType  field from the interface
 
-    contents = Schema(IMime, "zope.app.file.Mime",
-        title = _(u'The file data'),
-        description = _(u'The mime information and file data, which can be '
-                         'read as a file.'),
+    contents = Mime(
+        schema=IMime,
+        title = _(u'Mime file'),
+        description = _(u'The mime information and file data'),
         default=None,
         missing_value=None,
         required=False,

Modified: Zope3/branches/jhauser-filefieldwidget/src/zope/app/form/browser/__init__.py
===================================================================
--- Zope3/branches/jhauser-filefieldwidget/src/zope/app/form/browser/__init__.py	2005-01-24 14:59:47 UTC (rev 28920)
+++ Zope3/branches/jhauser-filefieldwidget/src/zope/app/form/browser/__init__.py	2005-01-24 15:14:59 UTC (rev 28921)
@@ -21,7 +21,7 @@
 
 from zope.app.form.browser.textwidgets import TextWidget, BytesWidget
 from zope.app.form.browser.textwidgets import TextAreaWidget, BytesAreaWidget
-from zope.app.form.browser.textwidgets import PasswordWidget
+from zope.app.form.browser.textwidgets import PasswordWidget, FileWidget
 from zope.app.form.browser.textwidgets import ASCIIWidget
 from zope.app.form.browser.textwidgets import IntWidget, FloatWidget
 from zope.app.form.browser.textwidgets import DatetimeWidget, DateWidget
@@ -33,11 +33,12 @@
 from zope.app.form.browser.schemawidgets import SchemaWidget
 
 # Widgets for file-based fields
-from zope.app.form.browser.filewidgets import FileWidget
-from zope.app.form.browser.filewidgets import MimeDataWidget
-from zope.app.form.browser.filewidgets import MimeDataEncodingWidget
-from zope.app.form.browser.filewidgets import MimeTypeWidget
-from zope.app.form.browser.filewidgets import MimeDisplayWidget
+from zope.app.form.browser.mimewidgets import MimeWidget
+from zope.app.form.browser.mimewidgets import MimeTextWidget
+from zope.app.form.browser.mimewidgets import MimeDataWidget
+from zope.app.form.browser.mimewidgets import MimeDataEncodingWidget
+from zope.app.form.browser.mimewidgets import MimeTypeWidget
+from zope.app.form.browser.mimewidgets import MimeDisplayWidget
 
 # Widgets for boolean fields
 from zope.app.form.browser.boolwidgets import CheckBoxWidget

Modified: Zope3/branches/jhauser-filefieldwidget/src/zope/app/form/browser/configure.zcml
===================================================================
--- Zope3/branches/jhauser-filefieldwidget/src/zope/app/form/browser/configure.zcml	2005-01-24 14:59:47 UTC (rev 28920)
+++ Zope3/branches/jhauser-filefieldwidget/src/zope/app/form/browser/configure.zcml	2005-01-24 15:14:59 UTC (rev 28921)
@@ -138,101 +138,112 @@
 
   <view
       type="zope.publisher.interfaces.browser.IBrowserRequest"
-      for="zope.schema.interfaces.ISchema"
+      for="zope.schema.interfaces.IASCII"
       provides="zope.app.form.interfaces.IInputWidget"
-      factory=".SchemaWidget"
+      factory=".BytesAreaWidget"
       permission="zope.Public"
       />
 
-<!-- TODO:
-     The IMime field Mime is replace by ISchema field called Schema
-     find a way where we can register special widgets for Schema fields.
-     Perhaps we have to use subdirective in editforms <widget>
   <view
       type="zope.publisher.interfaces.browser.IBrowserRequest"
-      for="zope.schema.interfaces.IMime"
-      provides="zope.app.form.interfaces.IDisplayWidget"
-      factory=".MimeDisplayWidget"
+      for="zope.schema.interfaces.IInt"
+      provides="zope.app.form.interfaces.IInputWidget"
+      factory=".IntWidget"
       permission="zope.Public"
       />
--->
+
   <view
       type="zope.publisher.interfaces.browser.IBrowserRequest"
-      for="zope.schema.interfaces.IMimeData"
+      for="zope.schema.interfaces.IFloat"
       provides="zope.app.form.interfaces.IInputWidget"
-      factory=".MimeDataWidget"
+      factory=".FloatWidget"
       permission="zope.Public"
       />
 
   <view
       type="zope.publisher.interfaces.browser.IBrowserRequest"
-      for="zope.schema.interfaces.IMimeDataEncoding"
+      for="zope.schema.interfaces.IDatetime"
       provides="zope.app.form.interfaces.IInputWidget"
-      factory=".MimeDataEncodingWidget"
+      factory=".DatetimeWidget"
       permission="zope.Public"
       />
 
   <view
       type="zope.publisher.interfaces.browser.IBrowserRequest"
-      for="zope.schema.interfaces.IMimeType"
+      for="zope.schema.interfaces.IDate"
       provides="zope.app.form.interfaces.IInputWidget"
-      factory=".MimeTypeWidget"
+      factory=".DateWidget"
       permission="zope.Public"
       />
 
   <view
       type="zope.publisher.interfaces.browser.IBrowserRequest"
-      for="zope.schema.interfaces.IASCII"
+      for="zope.schema.interfaces.IBool"
       provides="zope.app.form.interfaces.IInputWidget"
-      factory=".BytesAreaWidget"
+      factory=".CheckBoxWidget"
       permission="zope.Public"
       />
 
   <view
       type="zope.publisher.interfaces.browser.IBrowserRequest"
-      for="zope.schema.interfaces.IInt"
+      for="zope.schema.interfaces.IPassword"
       provides="zope.app.form.interfaces.IInputWidget"
-      factory=".IntWidget"
+      factory=".PasswordWidget"
       permission="zope.Public"
       />
 
+<!-- TODO:
+     The IMime field Mime is replace by ISchema field called Schema
+     find a way where we can register special widgets for Schema fields.
+     Perhaps we have to use subdirective in editforms <widget>
   <view
       type="zope.publisher.interfaces.browser.IBrowserRequest"
-      for="zope.schema.interfaces.IFloat"
+      for="zope.schema.interfaces.IMime"
+      provides="zope.app.form.interfaces.IDisplayWidget"
+      factory=".MimeDisplayWidget"
+      permission="zope.Public"
+      />
+-->
+
+  <!-- Schema input widgets -->
+  <view
+      type="zope.publisher.interfaces.browser.IBrowserRequest"
+      for="zope.schema.interfaces.ISchema"
       provides="zope.app.form.interfaces.IInputWidget"
-      factory=".FloatWidget"
+      factory=".SchemaWidget"
       permission="zope.Public"
       />
 
+  <!-- Mime input widgets -->
   <view
       type="zope.publisher.interfaces.browser.IBrowserRequest"
-      for="zope.schema.interfaces.IDatetime"
+      for="zope.schema.interfaces.IMime"
       provides="zope.app.form.interfaces.IInputWidget"
-      factory=".DatetimeWidget"
+      factory=".MimeWidget"
       permission="zope.Public"
       />
 
   <view
       type="zope.publisher.interfaces.browser.IBrowserRequest"
-      for="zope.schema.interfaces.IDate"
+      for="zope.schema.interfaces.IMimeData"
       provides="zope.app.form.interfaces.IInputWidget"
-      factory=".DateWidget"
+      factory=".MimeDataWidget"
       permission="zope.Public"
       />
 
   <view
       type="zope.publisher.interfaces.browser.IBrowserRequest"
-      for="zope.schema.interfaces.IBool"
+      for="zope.schema.interfaces.IMimeDataEncoding"
       provides="zope.app.form.interfaces.IInputWidget"
-      factory=".CheckBoxWidget"
+      factory=".MimeDataEncodingWidget"
       permission="zope.Public"
       />
 
   <view
       type="zope.publisher.interfaces.browser.IBrowserRequest"
-      for="zope.schema.interfaces.IPassword"
+      for="zope.schema.interfaces.IMimeType"
       provides="zope.app.form.interfaces.IInputWidget"
-      factory=".PasswordWidget"
+      factory=".MimeTypeWidget"
       permission="zope.Public"
       />
 
@@ -433,6 +444,5 @@
       factory=".source.SourceListInputWidget"
       permission="zope.Public"
       />
-     
 
 </configure>

Deleted: Zope3/branches/jhauser-filefieldwidget/src/zope/app/form/browser/filewidgets.py
===================================================================
--- Zope3/branches/jhauser-filefieldwidget/src/zope/app/form/browser/filewidgets.py	2005-01-24 14:59:47 UTC (rev 28920)
+++ Zope3/branches/jhauser-filefieldwidget/src/zope/app/form/browser/filewidgets.py	2005-01-24 15:14:59 UTC (rev 28921)
@@ -1,258 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2005 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.
-#
-##############################################################################
-"""Browser widgets with file-based input
-
-$Id$
-"""
-__docformat__ = 'restructuredtext'
-
-
-from zope.interface import implements
-
-from zope.app.form.interfaces import IInputWidget, ConversionError
-from zope.app.form.browser.widget import SimpleInputWidget, renderElement
-from zope.app.form import InputWidget
-from zope.app.form.browser.widget import BrowserWidget
-from zope.app.form.browser.textwidgets import BytesWidget
-from zope.app.form.browser.widget import DisplayWidget
-from zope.app.form.browser.textwidgets import TextWidget, escape
-from zope.app.form.browser.schemawidgets import SchemaWidget
-from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
-
-
-class MimeDataWidget(TextWidget):
-    """MimeDataWidget extracts the fileupload information from the session.
-    
-    The session is initiated from the MimeWidget and contains the fileupload.
-    The method _toFieldValue() reads the fileupload (input) from the session.
-    """
-    type = 'file'
-
-    default = ''
-    displayWidth = 20
-    displayMaxWidth = ""
-    extra = ''
-    style = ''
-    convert_missing_value = True
-
-    def __call__(self):
-        # XXX set the width to 40 to be sure to recognize this widget
-        displayMaxWidth = self.displayMaxWidth or 0
-        if displayMaxWidth > 0:
-            return renderElement(self.tag,
-                                 type=self.type,
-                                 name=self.name,
-                                 id=self.name,
-                                 cssClass=self.cssClass,
-                                 size=40,
-                                 maxlength=40,
-                                 extra=self.extra)
-        else:
-            return renderElement(self.tag,
-                                 type=self.type,
-                                 name=self.name,
-                                 id=self.name,
-                                 cssClass=self.cssClass,
-                                 size=40,
-                                 extra=self.extra)
-
-    def _toFieldValue(self, input):
-        if input == '':
-            return self.context.missing_value
-        try:
-            seek = input.seek
-            read = input.read
-        except AttributeError, e:
-            raise ConversionError('Form input is not a file object', e)
-        else:
-            seek(0)
-            data = read()
-            if data or getattr(input, 'filename', ''):
-                return data
-            else:
-                return self.context.missing_value
-
-#    def applyChanges(self, content):
-#        field = self.context
-#        value = self.getInputValue()
-#        if field.query(content, self) != value:
-#            field.set(content, value)
-#            return True
-#        else:
-#            return False
-
-    def applyChanges(self, content):
-        field = self.context
-        value = self.getInputValue()
-        # need to test for value, as an empty field is not an error, but
-        # the current file should not be replaced.
-        if value and (field.query(content, self) != value):
-            field.set(content, value)
-            return True
-        else:
-            return False
-
-
-# TODO: add better description.
-
-# till now we use a simply BytesWidget, later we can make use of a vocabulary
-# for list the encoding via a Choice field 
-class MimeDataEncodingWidget(BytesWidget):
-    """MimeDataEncodingWidget set the encoding on text-based data.
-    
-    If we have a file with a mime-type 'text/...' we can set the encoding.
-    """
-
-# till now we use a simply BytesWidget, later we can make use of a vocabulary
-# for list the encoding via a Choice field 
-class MimeTypeWidget(BytesWidget):
-    """MimeTypeWidget is used for to guess the mime-type.
-    
-    The session is initiated from the MimeWidget and contains the filename.
-    The method _toFieldValue() reads the filename (input) from the session
-    and finds the mime-type via the python mimetypes lib.
-    """
-    pass
-
-
-# TODO: I replaced the Mime field (IMime) with generic field Schem (ISchema)
-# we have to find a way where we can registrer this widget for IDisplay
-# Perhaps we can use the IMime interface which is used in the Schema field
-# See zope.app.file.interfaces.IFile.contents 
-class MimeDisplayWidget(DisplayWidget):
-    """Mime data display widget."""
-    # There need to be probably some widget options to determine how
-    # the file is displayed, e.g. as a download link.
-
-    def __call__(self):
-        if self._renderedValueSet():
-            content = self._data
-        else:
-            content = self.context.default
-
-        show = u"Filename %s, size in bytes: %s" (content.filename,
-                                                  content.getSize())
-        return renderElement("span", contents=escape(show))
-
-
-
-# TODO remove old implementations
-class FileWidget(SimpleInputWidget):
-    """File Widget"""
-
-    type = 'file'
-
-    default = ''
-    displayWidth = 20
-    displayMaxWidth = ""
-    extra = ''
-    style = ''
-    convert_missing_value = True
-
-    def __call__(self):
-        displayMaxWidth = self.displayMaxWidth or 0
-        if displayMaxWidth > 0:
-            return renderElement(self.tag,
-                                 type=self.type,
-                                 name=self.name,
-                                 id=self.name,
-                                 cssClass=self.cssClass,
-                                 size=self.displayWidth,
-                                 maxlength=displayMaxWidth,
-                                 extra=self.extra)
-        else:
-            return renderElement(self.tag,
-                                 type=self.type,
-                                 name=self.name,
-                                 id=self.name,
-                                 cssClass=self.cssClass,
-                                 size=self.displayWidth,
-                                 extra=self.extra)
-
-    def _toFieldValue(self, input):
-        if input == '':
-            return self.context.missing_value
-        try:
-            seek = input.seek
-            read = input.read
-        except AttributeError, e:
-            raise ConversionError('Form input is not a file object', e)
-        else:
-            seek(0)
-            data = read()
-            if data or getattr(input, 'filename', ''):
-                return data
-            else:
-                return self.context.missing_value
-
-# TODO: remove it
-class XXXMimeWidget(SimpleInputWidget):
-    u"""Mime file upload widget"""
-
-    type = 'file'
-
-    default = ''
-    displayWidth = 20
-    displayMaxWidth = ""
-    extra = ''
-    style = ''
-    convert_missing_value = True
-
-    def __call__(self):
-        # XXX set the width to 40 to be sure to recognize this widget
-        displayMaxWidth = self.displayMaxWidth or 0
-        if displayMaxWidth > 0:
-            return renderElement(self.tag,
-                                 type=self.type,
-                                 name=self.name,
-                                 id=self.name,
-                                 cssClass=self.cssClass,
-                                 size=40,
-                                 maxlength=40,
-                                 extra=self.extra)
-        else:
-            return renderElement(self.tag,
-                                 type=self.type,
-                                 name=self.name,
-                                 id=self.name,
-                                 cssClass=self.cssClass,
-                                 size=40,
-                                 extra=self.extra)
-
-    def _toFieldValue(self, input):
-        if input == '':
-            return self.context.missing_value
-        try:
-            seek = input.seek
-            read = input.read
-        except AttributeError, e:
-            raise ConversionError('Form input is not a file object', e)
-        else:
-            # if the FileUpload instance has no filename set, there is
-            # no upload.
-            if getattr(input, 'filename', ''):
-                return input
-            else:
-                return self.context.missing_value
-
-    def applyChanges(self, content):
-        field = self.context
-        value = self.getInputValue()
-        # need to test for value, as an empty field is not an error, but
-        # the current file should not be replaced.
-        if value and (field.query(content, self) != value):
-            field.set(content, value)
-            return True
-        else:
-            return False

Added: Zope3/branches/jhauser-filefieldwidget/src/zope/app/form/browser/ftests/test_schemawidget.py
===================================================================
--- Zope3/branches/jhauser-filefieldwidget/src/zope/app/form/browser/ftests/test_schemawidget.py	2005-01-24 14:59:47 UTC (rev 28920)
+++ Zope3/branches/jhauser-filefieldwidget/src/zope/app/form/browser/ftests/test_schemawidget.py	2005-01-24 15:14:59 UTC (rev 28921)
@@ -0,0 +1,82 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 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.
+#
+##############################################################################
+"""Test object widget
+
+$Id: test_objectwidget.py 26551 2004-07-15 07:06:37Z srichter $
+"""
+import unittest, doctest
+
+from zope.interface import Interface, implements
+from zope.publisher.browser import TestRequest
+from zope.schema import Schema, TextLine
+from zope.component.interfaces import IFactory
+from zope.component.factory import Factory
+from zope.app import zapi
+from zope.app.form.browser import SchemaWidget
+from zope.app.tests.functional import BrowserTestCase
+from zope.app.form.browser.tests import support
+from zope.app.tests import ztapi
+
+
+class ITestChild(Interface):
+    name = TextLine()
+    
+class TestChild(object):
+    implements(ITestChild)
+    
+    def __init__(self, name=''):
+        self.name = name
+
+
+class Test(BrowserTestCase, support.VerifyResults):
+    
+    def setUp(self):
+        BrowserTestCase.setUp(self)
+        util = zapi.getGlobalServices().getService(zapi.servicenames.Adapters)
+        ztapi.provideAdapter(None, ITestChild, TestChild)
+        self.field = Schema(ITestChild)
+
+    def test_new(self):
+        request = TestRequest()
+        widget = SchemaWidget(self.field, request)
+        self.assertEquals(int(widget.hasInput()), 0)
+        check_list = (
+            'input', 'name="field.name"'
+        )
+        self.verifyResult(widget(), check_list)
+
+    def test_edit(self):
+        request = TestRequest(form={
+            'field.name': u'fred'
+            })
+        widget = SchemaWidget(self.field, request)
+        self.assertEquals(int(widget.hasInput()), 1)
+        o = widget.getInputValue()
+        self.assertEquals(hasattr(o, 'name'), 1)
+        self.assertEquals(o.name, u'fred')
+        check_list = (
+            'input', 'name="field.name"', 'value="fred"',
+        )
+        self.verifyResult(widget(), check_list)
+
+def test_suite():
+    suite = unittest.TestSuite()
+    suite.addTest(unittest.makeSuite(Test))
+    return suite
+
+if __name__=='__main__':
+    unittest.main(defaultTest='test_suite')
+
+
+


Property changes on: Zope3/branches/jhauser-filefieldwidget/src/zope/app/form/browser/ftests/test_schemawidget.py
___________________________________________________________________
Name: svn:eol-style
   + native

Copied: Zope3/branches/jhauser-filefieldwidget/src/zope/app/form/browser/mimewidgets.py (from rev 28913, Zope3/branches/jhauser-filefieldwidget/src/zope/app/form/browser/filewidgets.py)
===================================================================
--- Zope3/branches/jhauser-filefieldwidget/src/zope/app/form/browser/filewidgets.py	2005-01-22 02:40:04 UTC (rev 28913)
+++ Zope3/branches/jhauser-filefieldwidget/src/zope/app/form/browser/mimewidgets.py	2005-01-24 15:14:59 UTC (rev 28921)
@@ -0,0 +1,158 @@
+##############################################################################
+#
+# Copyright (c) 2005 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.
+#
+##############################################################################
+"""Browser widgets with file-based input
+
+$Id$
+"""
+__docformat__ = 'restructuredtext'
+
+
+from zope.app.form.interfaces import IInputWidget, ConversionError
+from zope.app.form import InputWidget
+from zope.app.form import CustomWidgetFactory
+from zope.app.form.browser import BrowserWidget, DisplayWidget
+from zope.app.form.browser import BytesAreaWidget
+from zope.app.form.browser import BytesWidget
+from zope.app.form.browser import TextWidget
+from zope.app.form.browser import SchemaWidget
+from zope.app.form.browser.widget import SimpleInputWidget, renderElement
+from zope.app.form.browser.textwidgets import escape
+from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
+
+
+class MimeWidget(SchemaWidget):
+    """Default Mime field widget."""
+
+    _factoryId = "zope.app.file.Mime"
+
+
+class MimeTextWidget(MimeWidget):
+    """IFile edit view used in editform for text-based files."""
+
+    data_widget = CustomWidgetFactory(BytesAreaWidget)
+
+
+class MimeDataWidget(TextWidget):
+    """MimeDataWidget extracts the fileupload information from the session.
+    
+    The session is initiated from the MimeWidget and contains the fileupload.
+    The method _toFieldValue() reads the fileupload (input) from the session.
+    """
+    type = 'file'
+
+    default = ''
+    displayWidth = 20
+    displayMaxWidth = ""
+    extra = ''
+    style = ''
+    convert_missing_value = True
+
+    def __call__(self):
+        # XXX set the width to 40 to be sure to recognize this widget
+        displayMaxWidth = self.displayMaxWidth or 0
+        if displayMaxWidth > 0:
+            return renderElement(self.tag,
+                                 type=self.type,
+                                 name=self.name,
+                                 id=self.name,
+                                 cssClass=self.cssClass,
+                                 size=40,
+                                 maxlength=40,
+                                 extra=self.extra)
+        else:
+            return renderElement(self.tag,
+                                 type=self.type,
+                                 name=self.name,
+                                 id=self.name,
+                                 cssClass=self.cssClass,
+                                 size=40,
+                                 extra=self.extra)
+
+    def _toFieldValue(self, input):
+        if input == '':
+            return self.context.missing_value
+        try:
+            seek = input.seek
+            read = input.read
+        except AttributeError, e:
+            raise ConversionError('Form input is not a file object', e)
+        else:
+            seek(0)
+            data = read()
+            if data or getattr(input, 'filename', ''):
+                return data
+            else:
+                return self.context.missing_value
+
+#    def applyChanges(self, content):
+#        field = self.context
+#        value = self.getInputValue()
+#        if field.query(content, self) != value:
+#            field.set(content, value)
+#            return True
+#        else:
+#            return False
+
+    def applyChanges(self, content):
+        field = self.context
+        value = self.getInputValue()
+        # need to test for value, as an empty field is not an error, but
+        # the current file should not be replaced.
+        if value and (field.query(content, self) != value):
+            field.set(content, value)
+            return True
+        else:
+            return False
+
+
+# TODO: add better description.
+
+# till now we use a simply BytesWidget, later we can make use of a vocabulary
+# for list the encoding via a Choice field 
+class MimeDataEncodingWidget(BytesWidget):
+    """MimeDataEncodingWidget set the encoding on text-based data.
+    
+    If we have a file with a mime-type 'text/...' we can set the encoding.
+    """
+
+# till now we use a simply BytesWidget, later we can make use of a vocabulary
+# for list the encoding via a Choice field 
+class MimeTypeWidget(BytesWidget):
+    """MimeTypeWidget is used for to guess the mime-type.
+    
+    The session is initiated from the MimeWidget and contains the filename.
+    The method _toFieldValue() reads the filename (input) from the session
+    and finds the mime-type via the python mimetypes lib.
+    """
+    pass
+
+
+# TODO: I replaced the Mime field (IMime) with generic field Schem (ISchema)
+# we have to find a way where we can registrer this widget for IDisplay
+# Perhaps we can use the IMime interface which is used in the Schema field
+# See zope.app.file.interfaces.IFile.contents 
+class MimeDisplayWidget(DisplayWidget):
+    """Mime data display widget."""
+    # There need to be probably some widget options to determine how
+    # the file is displayed, e.g. as a download link.
+
+    def __call__(self):
+        if self._renderedValueSet():
+            content = self._data
+        else:
+            content = self.context.default
+
+        show = u"Filename %s, size in bytes: %s" (content.filename,
+                                                  content.getSize())
+        return renderElement("span", contents=escape(show))

Modified: Zope3/branches/jhauser-filefieldwidget/src/zope/app/form/browser/schemawidget.pt
===================================================================
--- Zope3/branches/jhauser-filefieldwidget/src/zope/app/form/browser/schemawidget.pt	2005-01-24 14:59:47 UTC (rev 28920)
+++ Zope3/branches/jhauser-filefieldwidget/src/zope/app/form/browser/schemawidget.pt	2005-01-24 15:14:59 UTC (rev 28921)
@@ -1,6 +1,6 @@
 <fieldset>
   <legend tal:content="context/legendTitle">The Legend</legend>
-  <tal:block repeat="widget context/subwidgets">
+  <div class="row" tal:repeat="widget context/subwidgets">
     <metal:block use-macro="context/@@form_macros/widget_row" />
-  </tal:block>
+  </div>
 </fieldset>

Modified: Zope3/branches/jhauser-filefieldwidget/src/zope/app/form/browser/schemawidgets.py
===================================================================
--- Zope3/branches/jhauser-filefieldwidget/src/zope/app/form/browser/schemawidgets.py	2005-01-24 14:59:47 UTC (rev 28920)
+++ Zope3/branches/jhauser-filefieldwidget/src/zope/app/form/browser/schemawidgets.py	2005-01-24 15:14:59 UTC (rev 28921)
@@ -1,6 +1,6 @@
 ##############################################################################
 #
-# Copyright (c) 2004 Zope Corporation and Contributors.
+# Copyright (c) 2005 Zope Corporation and Contributors.
 # All Rights Reserved.
 #
 # This software is subject to the provisions of the Zope Public License,
@@ -11,9 +11,9 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-"""Browser widgets for text-like data
+"""Browser widgets for schema like object value.
 
-$Id: objectwidget.py 26748 2004-07-24 05:51:58Z pruggera $
+$Id:$
 """
 __docformat__ = 'restructuredtext'
 
@@ -21,17 +21,14 @@
 from zope.schema import getFieldNamesInOrder
 from zope.component.interfaces import IFactory
 
-from zope.app.zapi import queryUtility
+from zope.app.zapi import queryUtility, getAdapter
 from zope.app.form.interfaces import IInputWidget
 from zope.app.form import InputWidget
 from zope.app.form.browser.widget import BrowserWidget
 from zope.app.form.utility import setUpEditWidgets, applyWidgetsChanges
 from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
 
-# TODO: remove it 
-from zope.proxy import isProxy
 
-
 class SchemaWidgetView:
 
     template = ViewPageTemplateFile('schemawidget.pt')
@@ -45,10 +42,23 @@
     
     
 class SchemaWidget(BrowserWidget, InputWidget):
-    """A widget over an Interface that contains Fields."""
+    """A widget for an schema/interface that contains Fields.
+    
+    This widgets needs a factory for build a temp object for
+    setup the fields and store the values in the addform.
+    
+    As default we use the default factory registred on the
+    schema. like: Interface(None).
+    
+    If you like to use another factory you can inherit from this 
+    widget and override the _factoryId attribute for define another
+    factor by the content type factory id.
+    """
 
     implements(IInputWidget)
 
+    _factoryId =  None
+
     def __init__(self, context, request, **kw):
         super(SchemaWidget, self).__init__(context, request)
 
@@ -58,8 +68,12 @@
         # factory used to create content that this widget (field)
         # represents, we get the factory id of a content type declared
         # in the schema field
-        factoryId = self.context.factoryId
-        self.factory = queryUtility(IFactory, factoryId)
+        if self._factoryId:
+            self.factory = queryUtility(IFactory, self._factoryId)
+        else:
+            # TODO: check if this is the right method for get the adapter 
+            # factory class
+            self.factory = self.context.schema(None).__class__
 
         # handle foo_widget specs being passed in
         self.names = getFieldNamesInOrder(self.context.schema)
@@ -84,7 +98,7 @@
         return self.view()
         
     def legendTitle(self):
-        return self.context.title or self.context.__name__
+        return self.context.description or self.context.title or self.context.__name__
 
     def getSubWidget(self, name):
         return getattr(self, '%s_widget' % name)
@@ -102,11 +116,16 @@
     def getInputValue(self):
         """Return converted and validated widget data.
 
+        TODO: remove first part of description
         The value for this field will be represented as an `ObjectStorage`
         instance which holds the subfield values as attributes. It will
         need to be converted by higher-level code into some more useful
         object (note that the default EditView calls `applyChanges`, which
         does this).
+        
+        New:
+        The getInputValue will directly call the values of the form
+        and apply the changes to the field of the subobjects.
         """
         content = self.factory()
         for name in self.names:
@@ -122,27 +141,10 @@
             # TODO: ObjectCreatedEvent here would be nice
             value = self.factory()
 
-        # apply sub changes, see if there *are* any changes
+        # apply sub widget changes, see if there *are* any changes
         # TODO: ObjectModifiedEvent here would be nice
         changes = applyWidgetsChanges(self, field.schema, target=value,
                                       names=self.names)
-
-        # TODO: check this
-        # We have a Subobject allready set in the init method. Don't replace 
-        # the subobject, just update it
-        
-        # if there's changes, then store the new value on the content
-        #print "start if changes"
-        #if changes:
-        #    print "field.set(content, value) "
-        #    print "   ... field ", field
-        #    print "       ... isProxy(field) ", isProxy(field)
-        #    print "   ... content ", content
-        #    print "       ... isProxy(content) ", isProxy(content)
-        #    print "   ... value ", value
-        #    print "       ... isProxy(value) ", isProxy(value)
-        #    field.set(content, value)
-
         return changes
 
     def hasInput(self):
@@ -165,5 +167,3 @@
         self._setUpEditWidgets()
         for name in self.names:
             self.getSubWidget(name).setRenderedValue(getattr(value, name, None))
-            
-

Modified: Zope3/branches/jhauser-filefieldwidget/src/zope/app/form/browser/textwidgets.py
===================================================================
--- Zope3/branches/jhauser-filefieldwidget/src/zope/app/form/browser/textwidgets.py	2005-01-24 14:59:47 UTC (rev 28920)
+++ Zope3/branches/jhauser-filefieldwidget/src/zope/app/form/browser/textwidgets.py	2005-01-24 15:14:59 UTC (rev 28921)
@@ -386,7 +386,48 @@
         raise NotImplementedError(
             'Cannot get a hidden tag for a password field')
 
+class FileWidget(TextWidget):
+    """File Widget"""
 
+    type = 'file'
+
+    def __call__(self):
+        displayMaxWidth = self.displayMaxWidth or 0
+        if displayMaxWidth > 0:
+            return renderElement(self.tag,
+                                 type=self.type,
+                                 name=self.name,
+                                 id=self.name,
+                                 cssClass=self.cssClass,
+                                 size=self.displayWidth,
+                                 maxlength=displayMaxWidth,
+                                 extra=self.extra)
+        else:
+            return renderElement(self.tag,
+                                 type=self.type,
+                                 name=self.name,
+                                 id=self.name,
+                                 cssClass=self.cssClass,
+                                 size=self.displayWidth,
+                                 extra=self.extra)
+
+    def _toFieldValue(self, input):
+        if input == '':
+            return self.context.missing_value
+        try:
+            seek = input.seek
+            read = input.read
+        except AttributeError, e:
+            raise ConversionError('Form input is not a file object', e)
+        else:
+            seek(0)
+            data = read()
+            if data or getattr(input, 'filename', ''):
+                return data
+            else:
+                return self.context.missing_value
+
+
 class IntWidget(TextWidget):
     displayWidth = 10
 

Modified: Zope3/branches/jhauser-filefieldwidget/src/zope/schema/__init__.py
===================================================================
--- Zope3/branches/jhauser-filefieldwidget/src/zope/schema/__init__.py	2005-01-24 14:59:47 UTC (rev 28920)
+++ Zope3/branches/jhauser-filefieldwidget/src/zope/schema/__init__.py	2005-01-24 15:14:59 UTC (rev 28921)
@@ -18,7 +18,7 @@
 from zope.schema._field import Field, Container, Iterable, Orderable
 from zope.schema._field import MinMaxLen, Choice
 from zope.schema._field import Bytes, ASCII, BytesLine
-from zope.schema._field import MimeData, MimeDataEncoding, MimeType
+from zope.schema._field import Mime, MimeData, MimeDataEncoding, MimeType
 from zope.schema._field import Text, TextLine, Bool, Int, Float
 from zope.schema._field import Tuple, List, Set
 from zope.schema._field import Password, Dict, Datetime, Date, SourceText

Modified: Zope3/branches/jhauser-filefieldwidget/src/zope/schema/_field.py
===================================================================
--- Zope3/branches/jhauser-filefieldwidget/src/zope/schema/_field.py	2005-01-24 14:59:47 UTC (rev 28920)
+++ Zope3/branches/jhauser-filefieldwidget/src/zope/schema/_field.py	2005-01-24 15:14:59 UTC (rev 28921)
@@ -33,7 +33,7 @@
 from zope.schema.interfaces import IBool, IInt, IFloat, IDatetime
 from zope.schema.interfaces import IChoice, ITuple, IList, ISet, IDict
 from zope.schema.interfaces import IPassword, IObject, IDate
-from zope.schema.interfaces import ISchema
+from zope.schema.interfaces import ISchema, IMime
 from zope.schema.interfaces import IURI, IId, IFromUnicode
 from zope.schema.interfaces import ISource, IVocabulary
 
@@ -539,14 +539,13 @@
 
     _type = None
     schema = None
-    factoryId = None
 
-    def __init__(self, schema, factoryId, **kw):
+    def __init__(self, schema, **kw):
         if not IInterface.providedBy(schema):
             raise WrongType
+        super(Schema, self).__init__(**kw)
             
         self.schema = schema
-        self.factoryId = factoryId
         super(Schema, self).__init__(**kw)
         
     def _validate(self, value):
@@ -555,6 +554,11 @@
             raise SchemaNotProvided
 
 
+class Mime(Schema):
+    __doc__ = IMime.__doc__
+    implements(IMime)
+
+
 class Dict(MinMaxLen, Iterable, Field):
     """A field representing a Dict."""
     implements(IDict)

Modified: Zope3/branches/jhauser-filefieldwidget/src/zope/schema/interfaces.py
===================================================================
--- Zope3/branches/jhauser-filefieldwidget/src/zope/schema/interfaces.py	2005-01-24 14:59:47 UTC (rev 28920)
+++ Zope3/branches/jhauser-filefieldwidget/src/zope/schema/interfaces.py	2005-01-24 15:14:59 UTC (rev 28921)
@@ -424,20 +424,16 @@
 class ISchema(IField):
     u"""Field containing an schema descriping the fields.
     
-    This is like a IObject field which defines and handles the factory itself.
     The Schema field is used for Object values. It gives a powerfull bridge
     to not only attributes as values. This makes it possible to define a simply
-    interface schema for schema based values.
+    interface schema for schema based objects.
     """
 
-    interface = Attribute("interface",
+    schema = Attribute("schema",
         _(u"The Interface that defines the Fields comprising the Object."))
 
-    factoryId = TextLine(
-        title=u"factoryId",
-        description=(u"The factory id which is used for to initalize the object."),
-        required=False,
-        default=None)
+class IMime(ISchema):
+    u"""Interface for Mime field"""
 
 # TODO: perhaps we should use TextLine for prevent inheriting IMinMaxLen
 class IMimeData(IBytes):



More information about the Zope3-Checkins mailing list