[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Content/Image/Views/Browser - ImageUpload.py:1.1 configure.zcml:1.10 edit.pt:1.4 i18n_edit.pt:1.2 ImageEdit.py:NONE

Jim Fulton jim@zope.com
Mon, 11 Nov 2002 16:08:13 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Content/Image/Views/Browser
In directory cvs.zope.org:/tmp/cvs-serv22201/Views/Browser

Modified Files:
	configure.zcml edit.pt i18n_edit.pt 
Added Files:
	ImageUpload.py 
Removed Files:
	ImageEdit.py 
Log Message:
Changed to use (single-line) Line field for content type.

Added an automatically-generated upload form that is customized with a
class to provide a custom widget (a file widget) for the data and to
provide size information.  The form is also custimized with a custom
template that adds size information. It uses macros from the base
template.

Had to provide a menu definition for I18nImage to avoid getting menu
definitions from IFile.



=== Added File Zope3/lib/python/Zope/App/OFS/Content/Image/Views/Browser/ImageUpload.py ===
##############################################################################
#
# 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.0 (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.
# 
##############################################################################
"""Define view component for image editing.

$Id: ImageUpload.py,v 1.1 2002/11/11 21:08:13 jim Exp $
"""
from Zope.App.OFS.Content.File.Views.Browser.FileUpload import FileUpload

class ImageUpload(FileUpload):
    """Image edit view mix-in that provides access to image size info"""

    def size(self):
        sx, sy = self.context.getImageSize()
        return "%s x %s pixels" % (sx > 0 and sx or 0, sx > 0 and sy or 0)
            

    def apply_update(self, data):
        """Apply user inputs

        These inputs have already been validated.

        Return a boolean indicating whether we changed anything,
        """

        unchanged = True

        # if we can compute the content type from the raw data, then
        # that overrides what the user provided, so set the content
        # type first.

        contentType = data.get('contentType')
        if contentType and contentType != self.context.contentType:
            self.context.contentType = contentType
            unchanged = False

        if 'data' in data:
            self.context.data = data['data']
            unchanged = False

        return unchanged


=== Zope3/lib/python/Zope/App/OFS/Content/Image/Views/Browser/configure.zcml 1.9 => 1.10 ===
--- Zope3/lib/python/Zope/App/OFS/Content/Image/Views/Browser/configure.zcml:1.9	Fri Jul 19 09:12:32 2002
+++ Zope3/lib/python/Zope/App/OFS/Content/Image/Views/Browser/configure.zcml	Mon Nov 11 16:08:13 2002
@@ -1,6 +1,7 @@
 <zopeConfigure
    xmlns="http://namespaces.zope.org/zope"
    xmlns:browser="http://namespaces.zope.org/browser"
+   xmlns:form="http://namespaces.zope.org/form"
    package="Zope.App.OFS.Content.Image">
 
 <browser:defaultView for=".Image.IImage." name="data" />
@@ -14,15 +15,14 @@
     allowed_attributes="__call__ tag"
     factory=".Views.Browser.ImageData." />
 
-<browser:view
-    for=".Image.IImage."
-    permission="Zope.ManageContent"
-    factory=".Views.Browser.ImageEdit.">
-
-  <browser:page name="editForm.html" attribute="form" />
-  <browser:page name="edit.html" attribute="action" />
-
-</browser:view>
+<form:edit
+    schema = ".Image.IImage."
+    name = "upload.html"
+    label = "Upload an image"
+    permission = "Zope.ManageContent"
+    class = ".Views.Browser.ImageUpload."
+    template = "Views/Browser/edit.pt"
+    />
 
 <!-- I18n Image View Directives -->
 
@@ -42,18 +42,29 @@
     permission="Zope.ManageContent"
     factory=".Views.Browser.I18nImageEdit.">
 
-  <browser:page name="editForm.html" template="Views/Browser/i18n_edit.pt" />
-  <browser:page name="edit.html" attribute="action" />
+  <browser:page name="upload.html" template="Views/Browser/i18n_edit.pt" />
+  <browser:page name="uploadAction.html" attribute="action" />
 
 </browser:view>
 
 <!-- tabs for image -->
 
 <browser:menuItems menu="zmi_views" for=".Image.IImage.">
-  <browser:menuItem title="Edit" action="editForm.html"/>
+  <browser:menuItem title="Upload" action="upload.html"/>
   <browser:menuItem title="View" action="."/>
   <browser:menuItem title="Role Permissions"
            action="AllRolePermissions.html"/>
+</browser:menuItems>
+
+<browser:menuItems menu="zmi_views" for=".I18nImage.II18nImage">
+
+  <!-- Keep the old "edit" form -->
+  <browser:menuItem title="Edit" action="upload.html"/>
+
+  <!-- Suppress upload form (from IFile) -->
+  <browser:menuItem title="Uload" action="upload.html"
+                    filter="python: 0" />
+
 </browser:menuItems>
 
 <browser:icon name="zmi_icon" for=".Image.IImage." file="Image_icon.gif" />


=== Zope3/lib/python/Zope/App/OFS/Content/Image/Views/Browser/edit.pt 1.3 => 1.4 ===
--- Zope3/lib/python/Zope/App/OFS/Content/Image/Views/Browser/edit.pt:1.3	Fri Jul 19 09:12:32 2002
+++ Zope3/lib/python/Zope/App/OFS/Content/Image/Views/Browser/edit.pt	Mon Nov 11 16:08:13 2002
@@ -2,48 +2,23 @@
   <body>
   <div metal:fill-slot="body">
 
-    <p>This edit form allows you to make changes to the properties 
-      of this image.</p>
+    <div metal:use-macro="view/generated_form/macros/body">
 
-    <div tal:condition="python: options.has_key('errors') and 
-                                options['errors']">
-      <span style="font-weight: bold">Errors:</span>
-      <div tal:repeat="error options/errors | nothing">
-        <span tal:replace="python: error[0].title" />: 
-        <span tal:replace="python: error[1].error_name" />
-      </div>
-    </div>
-    <br />
-
-    <form action="./edit.html" method="post" enctype="multipart/form-data">
-      <input type="hidden" name="nextURL" value=""
-          tal:attributes="value request/URL" />   
+    <form action=".">   
 
       <table class="EditTable">
-        <tr>
-          <th class="EditAttributeName">Size</th>
-	  <td class="EditAttributeValue">
-            <span tal:define="size context/getImageSize"
-                  tal:content="python: str(size[0]) + ' x ' + str(size[0])">
-              103 x 45</span> pixels
-          </td>            
+        <tr metal:fill-slot="extra_top">
+          <td class="EditAttributeName">Size</td>
+	  <td class="EditAttributeValue" tal:content="view/size"
+             >103 x 45 pixels</td>            
         </tr>
-        <tal:block repeat="field view/getFields">
-        <tr>
-          <th class="EditAttributeName"
-              tal:content="field/title">Title</th>
-	  <td class="EditAttributeValue"
-              tal:content="structure python: view.renderField(field)">
-            <input size="20" />
-          </td>            
-        </tr>
-	</tal:block>
       </table>
  
       <input type="submit" name="save" value="Save Changes" />
 
     </form>
 
+    </div>
   </div>
   </body>
 


=== Zope3/lib/python/Zope/App/OFS/Content/Image/Views/Browser/i18n_edit.pt 1.1 => 1.2 ===
--- Zope3/lib/python/Zope/App/OFS/Content/Image/Views/Browser/i18n_edit.pt:1.1	Tue Jun 25 06:54:24 2002
+++ Zope3/lib/python/Zope/App/OFS/Content/Image/Views/Browser/i18n_edit.pt	Mon Nov 11 16:08:13 2002
@@ -26,7 +26,8 @@
       </p>
 
 
-      <form action="edit.html" method="post" enctype="multipart/form-data">
+      <form action="uploadAction.html" method="post" 
+            enctype="multipart/form-data">
 
         <table class="EditTable">
 	  <tbody>

=== Removed File Zope3/lib/python/Zope/App/OFS/Content/Image/Views/Browser/ImageEdit.py ===