[Checkins] SVN: CMF/trunk/CMFDefault/ - added formlib based form for File and Image

Yvo Schubbe y.2007- at wcm-solutions.de
Wed Feb 14 07:38:29 EST 2007


Log message for revision 72569:
  - added formlib based form for File and Image

Changed:
  U   CMF/trunk/CMFDefault/browser/TODO.txt
  U   CMF/trunk/CMFDefault/browser/configure.zcml
  A   CMF/trunk/CMFDefault/browser/file.py
  U   CMF/trunk/CMFDefault/profiles/views_support/types/File.xml
  U   CMF/trunk/CMFDefault/profiles/views_support/types/Image.xml

-=-
Modified: CMF/trunk/CMFDefault/browser/TODO.txt
===================================================================
--- CMF/trunk/CMFDefault/browser/TODO.txt	2007-02-14 12:25:15 UTC (rev 72568)
+++ CMF/trunk/CMFDefault/browser/TODO.txt	2007-02-14 12:38:28 UTC (rev 72569)
@@ -84,21 +84,15 @@
       file_view.py -> FileView
       file_view_template.pt -> templates/file.pt
 
-  [ ] IMutableFile @@edit.html:
+  [x] IMutableFile @@edit.html:
 
-      file_edit_form.py -> FileEditView
-      file_edit_template.pt -> formlib based
-      file_edit_control.py -> formlib based
+      file_edit_form.py, image_edit_form.py -> FileEditView
+      file_edit_template.pt, image_edit_template.pt -> formlib based
+      file_edit_control.py, image_edit_control.py -> formlib based
 
   [ ] IImage @@view.html:
 
       image_view.py -> ImageView
       image_view_template.pt -> templates/image.pt
 
-  [ ] IMutableImage @@edit.html:
-
-      image_edit_form.py -> ImageEditView
-      image_edit_template.pt -> formlib based
-      image_edit_control.py -> formlib based
-
   [ ] complete this todo list

Modified: CMF/trunk/CMFDefault/browser/configure.zcml
===================================================================
--- CMF/trunk/CMFDefault/browser/configure.zcml	2007-02-14 12:25:15 UTC (rev 72568)
+++ CMF/trunk/CMFDefault/browser/configure.zcml	2007-02-14 12:38:28 UTC (rev 72569)
@@ -103,7 +103,17 @@
       permission="cmf.ModifyPortalContent"
       />
 
+  <adapter factory=".file.FileSchemaAdapter"/>
+
   <browser:page
+      for="..interfaces.IMutableFile"
+      layer="..interfaces.ICMFDefaultSkin"
+      name="edit.html"
+      class=".file.FileEditView"
+      permission="cmf.ModifyPortalContent"
+      />
+
+  <browser:page
       for="*"
       layer="..interfaces.ICMFDefaultSkin"
       name="form_widget"

Added: CMF/trunk/CMFDefault/browser/file.py
===================================================================
--- CMF/trunk/CMFDefault/browser/file.py	2007-02-14 12:25:15 UTC (rev 72568)
+++ CMF/trunk/CMFDefault/browser/file.py	2007-02-14 12:38:28 UTC (rev 72569)
@@ -0,0 +1,88 @@
+##############################################################################
+#
+# Copyright (c) 2007 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 views for files.
+
+$Id$
+"""
+
+from zope.component import adapts
+from zope.formlib import form
+from zope.interface import implements
+from zope.interface import Interface
+from zope.schema import ASCIILine
+from zope.schema import Bytes
+from zope.schema import Text
+from zope.schema import TextLine
+
+from Products.CMFDefault.formlib.form import ContentEditFormBase
+from Products.CMFDefault.formlib.schema import ProxyFieldProperty
+from Products.CMFDefault.formlib.schema import SchemaAdapterBase
+from Products.CMFDefault.interfaces import IMutableFile
+from Products.CMFDefault.utils import Message as _
+
+
+class IFileSchema(Interface):
+
+    """Schema for file views.
+    """
+
+    title = TextLine(
+        title=_(u'Title'),
+        readonly=True)
+
+    description = Text(
+        title=_(u'Description'),
+        readonly=True)
+
+    format = ASCIILine(
+        title=_(u'Content type'),
+        readonly=True)
+
+    upload = Bytes(
+        title=_(u'Upload'),
+        required=False)
+
+
+class FileSchemaAdapter(SchemaAdapterBase):
+
+    """Adapter for IMutableFile.
+    """
+
+    adapts(IMutableFile)
+    implements(IFileSchema)
+
+    title = ProxyFieldProperty(IFileSchema['title'], 'Title')
+    description = ProxyFieldProperty(IFileSchema['description'],
+                                     'Description')
+    format = ProxyFieldProperty(IFileSchema['format'], 'Format')
+    upload = ProxyFieldProperty(IFileSchema['upload'],
+                                'data', 'manage_upload')
+
+
+class FileEditView(ContentEditFormBase):
+
+    """Edit view for IMutableFile.
+    """
+
+    form_fields = form.FormFields(IFileSchema)
+
+    def setUpWidgets(self, ignore_request=False):
+        super(FileEditView,
+              self).setUpWidgets(ignore_request=ignore_request)
+        self.widgets['description'].height = 3
+        self.widgets['upload'].displayWidth = 60
+
+    def _handle_success(self, action, data):
+        if not data.get('upload'):
+            del data['upload']
+        return super(FileEditView, self)._handle_success(action, data)


Property changes on: CMF/trunk/CMFDefault/browser/file.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: CMF/trunk/CMFDefault/profiles/views_support/types/File.xml
===================================================================
--- CMF/trunk/CMFDefault/profiles/views_support/types/File.xml	2007-02-14 12:25:15 UTC (rev 72568)
+++ CMF/trunk/CMFDefault/profiles/views_support/types/File.xml	2007-02-14 12:38:28 UTC (rev 72569)
@@ -1,4 +1,5 @@
 <?xml version="1.0"?>
 <object name="File">
+ <alias from="file_edit_form" to="@@edit.html"/>
  <alias from="metadata_edit_form" to="@@properties.html"/>
 </object>

Modified: CMF/trunk/CMFDefault/profiles/views_support/types/Image.xml
===================================================================
--- CMF/trunk/CMFDefault/profiles/views_support/types/Image.xml	2007-02-14 12:25:15 UTC (rev 72568)
+++ CMF/trunk/CMFDefault/profiles/views_support/types/Image.xml	2007-02-14 12:38:28 UTC (rev 72569)
@@ -1,4 +1,5 @@
 <?xml version="1.0"?>
 <object name="Image">
+ <alias from="image_edit_form" to="@@edit.html"/>
  <alias from="metadata_edit_form" to="@@properties.html"/>
 </object>



More information about the Checkins mailing list