[Zope3-checkins] CVS: Zope3/src/zope/app/file/browser -
__init__.py:1.2 configure.zcml:1.2 file.py:1.2
file_icon.gif:1.2 file_upload.hlp:1.2 image.py:1.2
image_edit.pt:1.2 image_icon.gif:1.2
Philipp von Weitershausen
philikon at philikon.de
Tue Feb 24 11:50:20 EST 2004
Update of /cvs-repository/Zope3/src/zope/app/file/browser
In directory cvs.zope.org:/tmp/cvs-serv26210/src/zope/app/file/browser
Added Files:
__init__.py configure.zcml file.py file_icon.gif
file_upload.hlp image.py image_edit.pt image_icon.gif
Log Message:
Combined the File and Image content types in their own package below
zope.app, including their interfaces and browser views.
=== Zope3/src/zope/app/file/browser/__init__.py 1.1 => 1.2 ===
--- /dev/null Tue Feb 24 11:50:19 2004
+++ Zope3/src/zope/app/file/browser/__init__.py Tue Feb 24 11:49:48 2004
@@ -0,0 +1,2 @@
+#
+# This file is necessary to make this directory a package.
=== Zope3/src/zope/app/file/browser/configure.zcml 1.1 => 1.2 ===
--- /dev/null Tue Feb 24 11:50:19 2004
+++ Zope3/src/zope/app/file/browser/configure.zcml Tue Feb 24 11:49:48 2004
@@ -0,0 +1,147 @@
+<configure
+ xmlns='http://namespaces.zope.org/zope'
+ xmlns:browser='http://namespaces.zope.org/browser'
+ xmlns:help="http://namespaces.zope.org/help"
+ i18n_domain='zope'
+ >
+
+ <!-- directives for File -->
+
+ <browser:view
+ name="_traverse"
+ for="zope.app.file.interfaces.IFileContent"
+ class="zope.app.publication.traversers.FileContentTraverser"
+ permission="zope.Public"
+ />
+
+ <browser:editform
+ name="edit.html"
+ schema="zope.app.file.interfaces.IFile"
+ label="Change a file"
+ usage="objectview"
+ permission="zope.ManageContent"
+ class=".file.FileTextEdit"
+ />
+
+ <browser:menuItem
+ menu="zmi_views" title="Edit"
+ for="zope.app.file.interfaces.IFile"
+ action="edit.html"
+ filter="python:context.contentType.startswith('text/')"
+ permission="zope.ManageContent" />
+
+
+ <browser:editform
+ name="upload.html"
+ menu="zmi_views" title="Upload"
+ schema="zope.app.file.interfaces.IFile"
+ label="Upload a file"
+ permission="zope.ManageContent"
+ />
+
+ <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:addform
+ schema="zope.app.file.interfaces.IFile"
+ label="Add a File"
+ content_factory="zope.app.file.File"
+ name="zope.app.file.File"
+ permission="zope.ManageContent"
+ />
+
+ <browser:icon
+ name="zmi_icon"
+ for="zope.app.file.interfaces.IFile"
+ file="file_icon.gif"
+ />
+
+ <help:register
+ id="file_upload"
+ title="File Upload Screen"
+ parent="ui"
+ for="zope.app.file.interfaces.IFile"
+ view="upload.html"
+ doc_path="./file_upload.hlp"
+ />
+
+
+ <!-- Directives for Image -->
+
+ <browser:editform
+ schema="zope.app.file.interfaces.IImage"
+ name="upload.html"
+ menu="zmi_views" title="Upload"
+ label="Upload an image"
+ permission="zope.ManageContent"
+ class=".image.ImageUpload"
+ template="image_edit.pt"
+ />
+
+ <browser:page
+ name="index.html"
+ for="zope.app.file.interfaces.IImage"
+ permission="zope.View"
+ allowed_attributes="__call__ tag"
+ class=".image.ImageData"
+ />
+
+ <browser:icon
+ name="zmi_icon"
+ for="zope.app.file.interfaces.IImage"
+ file="image_icon.gif"
+ />
+
+ <browser:addMenuItem
+ class="zope.app.file.image.Image"
+ title="Image"
+ description="An Image"
+ permission="zope.ManageContent"
+ view="zope.app.file.Image"
+ />
+
+ <browser:addform
+ schema="zope.app.file.interfaces.IImage"
+ label="Add a Image"
+ content_factory="zope.app.file.image.Image"
+ name="zope.app.file.Image"
+ permission="zope.ManageContent"
+ />
+
+
+ <!-- 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"
+ />
+
+ <browser:page
+ for="zope.app.file.interfaces.IImage"
+ name="preview.html"
+ template="preview.pt"
+ permission="zope.ManageContent"
+ menu="zmi_views" title="Preview"
+ />
+
+ </configure>
+
+</configure>
=== Zope3/src/zope/app/file/browser/file.py 1.1 => 1.2 ===
--- /dev/null Tue Feb 24 11:50:19 2004
+++ Zope3/src/zope/app/file/browser/file.py Tue Feb 24 11:49:48 2004
@@ -0,0 +1,41 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""File views.
+
+$Id$
+"""
+from zope.app.browser.form.widget import BytesAreaWidget
+from zope.app.form.widget import CustomWidgetFactory
+
+__metaclass__ = type
+
+class FileView:
+
+ def show(self):
+ """Call the File"""
+ request = self.request
+ if request is not None:
+ request.response.setHeader('Content-Type',
+ self.context.getContentType())
+ request.response.setHeader('Content-Length',
+ self.context.getSize())
+
+ return self.context.getData()
+
+
+class FileTextEdit:
+ """File editing mix-in that uses a file-upload widget.
+ """
+
+ data_widget = CustomWidgetFactory(BytesAreaWidget)
=== Zope3/src/zope/app/file/browser/file_icon.gif 1.1 => 1.2 ===
<Binary-ish file>
=== Zope3/src/zope/app/file/browser/file_upload.hlp 1.1 => 1.2 ===
--- /dev/null Tue Feb 24 11:50:19 2004
+++ Zope3/src/zope/app/file/browser/file_upload.hlp Tue Feb 24 11:49:48 2004
@@ -0,0 +1 @@
+This screen allows to upload new file data.
\ No newline at end of file
=== Zope3/src/zope/app/file/browser/image.py 1.1 => 1.2 ===
--- /dev/null Tue Feb 24 11:50:19 2004
+++ Zope3/src/zope/app/file/browser/image.py Tue Feb 24 11:49:48 2004
@@ -0,0 +1,127 @@
+##############################################################################
+#
+# 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.app.size import byteDisplay
+from zope.app.event.objectevent import ObjectModifiedEvent
+from zope.app.event import publish
+from zope.app.publisher.browser import BrowserView
+
+class ImageData(BrowserView):
+
+ def __call__(self):
+ image = self.context
+ if self.request is not None:
+ self.request.response.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
+
+
+class ImageUpload:
+ """Image edit view mix-in that provides access to image size info"""
+
+ def size(self):
+ sx, sy = self.context.getImageSize()
+ if sx < 0:
+ sx = '?'
+ if sy < 0:
+ sy = '?'
+ return "%s x %s pixels, %s" % (
+ sx, sy, byteDisplay(self.context.getSize())
+ )
+
+ 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
+
+ if not unchanged:
+ publish(self.context, ObjectModifiedEvent(self.context))
+
+ return unchanged
=== Zope3/src/zope/app/file/browser/image_edit.pt 1.1 => 1.2 ===
--- /dev/null Tue Feb 24 11:50:19 2004
+++ Zope3/src/zope/app/file/browser/image_edit.pt Tue Feb 24 11:49:48 2004
@@ -0,0 +1,26 @@
+<html metal:use-macro="views/standard_macros/page">
+<body>
+<div metal:fill-slot="body">
+
+ <div metal:use-macro="view/generated_form/macros/body">
+
+ <form action=".">
+
+ <table metal:fill-slot="extra_top">
+ <tr>
+ <td i18n:translate="">Size</td>
+ <td tal:content="view/size" i18n:translate=""
+ >103 x 45 pixels, 43KB</td>
+ </tr>
+ </table>
+
+ <input type="submit" name="save" value="Save Changes"
+ i18n:attributes="value save-changes-button"/>
+
+ </form>
+
+ </div>
+</div>
+</body>
+
+</html>
=== Zope3/src/zope/app/file/browser/image_icon.gif 1.1 => 1.2 ===
<Binary-ish file>
More information about the Zope3-Checkins
mailing list