[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/Content/Image/Views/Browser - ImageData.py:1.2 ImageEdit.py:1.2 __init__.py:1.2 browser.zcml:1.2 edit.pt:1.2

Jim Fulton jim@zope.com
Mon, 10 Jun 2002 19:28:35 -0400


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

Added Files:
	ImageData.py ImageEdit.py __init__.py browser.zcml edit.pt 
Log Message:
Merged Zope-3x-branch into newly forked Zope3 CVS Tree.


=== Zope3/lib/python/Zope/App/OFS/Content/Image/Views/Browser/ImageData.py 1.1 => 1.2 ===
+#
+# 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 naive file editing.
+
+$Id$
+"""
+
+from Zope.Publisher.Browser.BrowserView import BrowserView
+from Zope.App.PageTemplate import ViewPageTemplateFile
+
+class ImageData(BrowserView):
+
+    def __call__(self):        
+        image = self.context
+        if self.request is not None:
+            self.request.getResponse().setHeader('content-type',
+                                                 image.getContentType()) 
+        return image.getData()
+
+
+    def tag(self, height=None, width=None, alt=None,
+            scale=0, xscale=0, yscale=0, css_class=None, **args):
+        """
+        Generate an HTML IMG tag for this image, with customization.
+        Arguments to self.tag() can be any valid attributes of an IMG tag.
+        'src' will always be an absolute pathname, to prevent redundant
+        downloading of images. Defaults are applied intelligently for
+        'height', 'width', and 'alt'. If specified, the 'scale', 'xscale',
+        and 'yscale' keyword arguments will be used to automatically adjust
+        the output height and width values of the image tag.
+
+        Since 'class' is a Python reserved word, it cannot be passed in
+        directly in keyword arguments which is a problem if you are
+        trying to use 'tag()' to include a CSS class. The tag() method
+        will accept a 'css_class' argument that will be converted to
+        'class' in the output tag to work around this.
+        """
+        if width is None:
+            width=self.context.getImageSize()[0]
+        if height is None:
+            height = self.context.getImageSize()[1]
+
+        # Auto-scaling support
+        xdelta = xscale or scale
+        ydelta = yscale or scale
+
+        if xdelta and width:
+            width = str(int(round(int(width) * xdelta)))
+        if ydelta and height:
+            height = str(int(round(int(height) * ydelta)))
+
+        result='<img src="%s"' % (self.absolute_url())
+
+        if alt is None:
+            alt=getattr(self, 'title', '')
+        result = '%s alt="%s"' % (result, alt)
+
+        if height is not None:
+            result = '%s height="%s"' % (result, height)
+
+        if width is not None:
+            result = '%s width="%s"' % (result, width)
+
+        if not 'border' in [a.lower() for a in args.keys()]:
+            result = '%s border="0"' % result
+
+        if css_class is not None:
+            result = '%s class="%s"' % (result, css_class)
+
+        for key in args.keys():
+            value = args.get(key)
+            result = '%s %s="%s"' % (result, key, value)
+
+        return '%s />' % result


=== Zope3/lib/python/Zope/App/OFS/Content/Image/Views/Browser/ImageEdit.py 1.1 => 1.2 ===
+#
+# 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.
+
+Revision Information:
+$Id$
+"""
+
+from Zope.App.Formulator.Form import Form
+from Zope.App.PageTemplate import ViewPageTemplateFile
+
+
+class ImageEdit(Form):
+
+    __implements__ = Form.__implements__
+
+    name = 'editForm'     
+    title = 'Edit Form'
+    description = ('This edit form allows you to make changes to the ' +
+                   'properties of this image.')
+
+    _fieldViewNames = ['ContentTypeFieldView', 'DataFieldView']
+    template = ViewPageTemplateFile('edit.pt')
+    
+    def getImageSize(self):
+        size=self.context.getImageSize()
+        return "%d x %d" % (size[0], size[1])
+ 


=== Zope3/lib/python/Zope/App/OFS/Content/Image/Views/Browser/__init__.py 1.1 => 1.2 ===
+#
+# 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.
+# 
+##############################################################################
+"""
+
+$Id$
+"""


=== Zope3/lib/python/Zope/App/OFS/Content/Image/Views/Browser/browser.zcml 1.1 => 1.2 ===
+   xmlns='http://namespaces.zope.org/zope'
+   xmlns:security='http://namespaces.zope.org/security'
+   xmlns:browser='http://namespaces.zope.org/browser'
+>
+
+  <!-- Image View Directives -->
+
+  <browser:defaultView 
+      name="data"
+      for="Zope.App.OFS.Content.Image.Image.IImage."
+      permission="Zope.View"
+      allowed_attributes="__call__ tag"
+      factory=".ImageData." />
+
+  <browser:view
+      for="Zope.App.OFS.Content.Image.Image.IImage."
+      permission="Zope.ManageContent"
+      factory=".ImageEdit.">
+
+    <browser:page
+        name="editForm.html"
+        attribute="index" />
+    <browser:page
+        name="edit.html"
+        attribute="action" />
+  </browser:view>
+
+
+  <!-- Formulator directives -->
+
+  <browser:view
+      name="DataFieldView"
+      for="Zope.App.OFS.Content.Image.Image.IImage."
+      factory="Zope.App.OFS.Content.Image.ImageFields.DataField. 
+               Zope.App.Formulator.Widgets.Browser.FileWidget." />
+
+  <browser:view
+      name="ContentTypeFieldView"
+      for="Zope.App.OFS.Content.Image.Image.IImage."
+      factory="Zope.App.OFS.Content.Image.ImageFields.ContentTypeField. 
+               Zope.App.Formulator.Widgets.Browser.TextWidget." />
+
+</zopeConfigure>


=== Zope3/lib/python/Zope/App/OFS/Content/Image/Views/Browser/edit.pt 1.1 => 1.2 ===
+  <head>
+    <style metal:fill-slot="headers" type="text/css">
+      <!--
+      .ContentIcon {
+	  width: 20px;
+      }
+      
+      .ContentTitle {
+	  text-align: left;
+      }
+      -->
+    </style>
+  </head>
+
+  <body>
+    <div metal:fill-slot="body">
+
+ 
+      <p tal:content="options/msg | nothing">
+        Message will go here.
+      </p>
+
+      <p tal:content="view/description">
+        Description of the Form.
+      </p>
+
+
+      <div tal:condition="python: options.has_key('errors') 
+                                  and options['errors']">
+        Errors:
+        <div tal:repeat="error options/errors | nothing"
+             tal:content="error">Foo </div>
+      </div>
+
+      <form action="edit.html" method="post" enctype="multipart/form-data">
+
+        <table class="EditTable">      
+	  <tbody>   
+  
+	    <tr>
+	      <th class="EditAttributeName">Size</th>
+	      <td class="EditAttributeValue"
+          	  tal:content="view/getImageSize">
+              </td>
+	    </tr>
+  
+	    <tr tal:repeat="fieldView python:view.getFieldViews(request)">
+	      <th class="EditAttributeName"
+                tal:content="python: fieldView.context.getValue('title')">
+                Title</th>
+	      <td class="EditAttributeValue"
+	          tal:content="structure fieldView/render"><input />
+              </td>
+	    </tr>
+  
+	  </tbody>     
+      </table>
+
+      <input type="submit" name="edit" value="Save Changes">
+
+      </form> 
+
+    </div>
+  </body>
+</html>
+
+