[Zope3-checkins] SVN: Zope3/branches/jhauser-filefieldwidget/src/zope/app/f First working mime widget hack.

Roger Ineichen roger at projekt01.ch
Sat Jan 22 06:53:36 EST 2005


Log message for revision 28915:
  First working mime widget hack.
  Fixed addFile.html, upload.html
  TODO:
  Fix tests, check Schema widget, make sure we canhandle the proxied 
  object and don't replace the MimeData instance on contents if we 
  use the Schema widget.

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/file.py
  U   Zope3/branches/jhauser-filefieldwidget/src/zope/app/form/browser/schemawidgets.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-22 11:16:29 UTC (rev 28914)
+++ Zope3/branches/jhauser-filefieldwidget/src/zope/app/file/browser/configure.zcml	2005-01-22 11:53:36 UTC (rev 28915)
@@ -59,6 +59,14 @@
       permission="zope.ManageContent"
       />
 
+  <browser:page
+      for="zope.app.file.interfaces.IFile"
+      name="index.html"
+      permission="zope.View"
+      class=".file.NewStyleFileView"
+      attribute="show"
+      />
+
 <!-- BBB: old style files -->
 
   <browser:menuItem
@@ -90,14 +98,17 @@
       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" />
+      attribute="show"
+      />
+-->
 
-
   <browser:addMenuItem
       class="zope.app.file.File"
       title="File"

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-22 11:16:29 UTC (rev 28914)
+++ Zope3/branches/jhauser-filefieldwidget/src/zope/app/file/browser/file.py	2005-01-22 11:53:36 UTC (rev 28915)
@@ -28,6 +28,24 @@
 __docformat__ = 'restructuredtext'
 
 
+class NewStyleFileView(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())
+
+        # TODO: use self.context.open('r').read() instead directly
+        # 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()
+
+
 class FileView(object):
 
     def show(self):

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-22 11:16:29 UTC (rev 28914)
+++ Zope3/branches/jhauser-filefieldwidget/src/zope/app/file/browser/ftests.py	2005-01-22 11:53:36 UTC (rev 28915)
@@ -79,8 +79,9 @@
         self.addFile()
         response = self.publish(
             '/file/@@edit.html',
-            form={'field.data': u'<h1>A File</h1>',
-                  'field.contentType': u'text/plain',
+            form={'field.contents.data': u'<h1>A File</h1>',
+                  'field.contents.contentType': u'text/plain',
+                  'field.contents.encoding': u'',
                   'UPDATE_SUBMIT': u'Edit'},
             basic='mgr:mgrpw')
         self.assertEqual(response.getStatus(), 200)
@@ -91,7 +92,7 @@
         self.assert_(escape(u'<h1>A File</h1>') in body)
         root = self.getRootFolder()
         file = root['file']
-        self.assertEqual(file.data, '<h1>A File</h1>')
+        self.assertEqual(file.open('r').read(), '<h1>A File</h1>')
         self.assertEqual(file.contentType, 'text/plain')
 
     def testUploadForm(self):
@@ -111,9 +112,9 @@
         self.addFile()
         response = self.publish(
             '/file/@@fileupload.html',
-            form={'field.contents': StringIO('<h1>A file</h1>'),
-                  'field.contentType': u'text/plain',
-                  'field.encoding': u'UTF-8',
+            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')
         self.assertEqual(response.getStatus(), 200)
@@ -124,7 +125,7 @@
         self.failIf(escape(u'<h1>A File</h1>') in body)
         root = self.getRootFolder()
         file = root['file']
-        self.assertEqual(file.contents, '<h1>A file</h1>')
+        self.assertEqual(file.open('r').read(), '<h1>A file</h1>')
         self.assertEqual(file.contentType, 'text/plain')
         
     def testIndex(self):

Modified: Zope3/branches/jhauser-filefieldwidget/src/zope/app/file/configure.zcml
===================================================================
--- Zope3/branches/jhauser-filefieldwidget/src/zope/app/file/configure.zcml	2005-01-22 11:16:29 UTC (rev 28914)
+++ Zope3/branches/jhauser-filefieldwidget/src/zope/app/file/configure.zcml	2005-01-22 11:53:36 UTC (rev 28915)
@@ -35,45 +35,43 @@
        />
   </content>
 
-  <content class=".file.ReadFileStorage">
+  <!-- handle the mime field value as content -->
+  <content class=".file.Mime">
 
+    <factory
+        id="zope.app.file.Mime"
+        title="Mime field Value"
+        description="Mime field Value" />
+
     <require
         permission="zope.View"
-        interface=".interfaces.IReadFileAccess"
+        interface="zope.app.file.interfaces.IMime"
         />
 
-  </content>
-
-  <content class=".file.WriteFileStorage">
-
     <require
         permission="zope.ManageContent"
-        interface=".interfaces.IWriteFileAccess"
+        set_schema="zope.app.file.interfaces.IMime"
         />
 
   </content>
 
+  <class class=".file.ReadFileStorage">
 
-
-  <!-- handle the mime field value as content -->
-  <content class=".file.Mime">
-
-    <factory
-        id="zope.app.file.Mime"
-        title="Mime field Value"
-        description="Mime field Value" />
-
     <require
         permission="zope.View"
-        interface="zope.app.file.interfaces.IMime"
+        interface=".interfaces.IReadFileAccess"
         />
 
+  </class>
+
+  <class class=".file.WriteFileStorage">
+
     <require
         permission="zope.ManageContent"
-        set_schema="zope.app.file.interfaces.IMime"
+        interface=".interfaces.IWriteFileAccess"
         />
 
-  </content>
+  </class>
 
   <adapter 
       for=".interfaces.IFile"

Modified: Zope3/branches/jhauser-filefieldwidget/src/zope/app/file/file.py
===================================================================
--- Zope3/branches/jhauser-filefieldwidget/src/zope/app/file/file.py	2005-01-22 11:16:29 UTC (rev 28914)
+++ Zope3/branches/jhauser-filefieldwidget/src/zope/app/file/file.py	2005-01-22 11:53:36 UTC (rev 28915)
@@ -628,6 +628,8 @@
     def _setContents(self, contents):
         self._contents = contents
 
+    # TODO: How can we integrate security in this method
+    # We must support read and wirte permission on this method
     def open(self, mode='r'):
         """return a file-like object for reading or updating the file value.
         """

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-22 11:16:29 UTC (rev 28914)
+++ Zope3/branches/jhauser-filefieldwidget/src/zope/app/form/browser/schemawidgets.py	2005-01-22 11:53:36 UTC (rev 28915)
@@ -118,6 +118,7 @@
         print "applyChanges"
         field = self.context
         print "field = self.context ", self.context
+        print "content ", content
 
         # create our new object value
         value = field.query(content, None)
@@ -131,13 +132,29 @@
         # apply sub changes, see if there *are* any changes
         # TODO: ObjectModifiedEvent here would be nice
         print "self ", self
+        print "isProxy(self) ", isProxy(self)
+        print "isProxy(value) ", isProxy(value)
+        print "isProxy(field) ", isProxy(field)
+        print "isProxy(content) ", isProxy(content)
         print "self.names ", self.names
         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
-        if changes:
-            field.set(content, value)
+        #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
 



More information about the Zope3-Checkins mailing list