[Zope3-checkins] CVS: Zope3/src/zope/app/file/browser - __init__.py:1.1.2.1 configure.zcml:1.1.2.1 file.py:1.1.2.1 file_icon.gif:1.1.2.1 file_upload.hlp:1.1.2.1 image.py:1.1.2.1 image_edit.pt:1.1.2.1 image_icon.gif:1.1.2.1

Philipp von Weitershausen philikon at philikon.de
Fri Feb 20 14:39:49 EST 2004


Update of /cvs-repository/Zope3/src/zope/app/file/browser
In directory cvs.zope.org:/tmp/cvs-serv21299/browser

Added Files:
      Tag: philikon-movecontent-branch
	__init__.py configure.zcml file.py file_icon.gif 
	file_upload.hlp image.py image_edit.pt image_icon.gif 
Log Message:
File and Image content types live in zope.app.file now.


=== Added File Zope3/src/zope/app/file/browser/__init__.py ===
#
# This file is necessary to make this directory a package.


=== Added File Zope3/src/zope/app/file/browser/configure.zcml ===
<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=".interfaces.IFile"
      name="preview.html"
      menu="zmi_views" title="Preview"
      template="preview.pt"
      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"
      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:page
      for="zope.app.file.interfaces.IImage"
      name="preview.html"
      menu="zmi_views" title="Preview"
      template="preview.pt"
      permission="zope.ManageContent"
      /-->

  <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"
      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"
      />

</configure>


=== Added File Zope3/src/zope/app/file/browser/file.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.
#
##############################################################################
"""File views.

$Id: file.py,v 1.1.2.1 2004/02/20 19:39:47 philikon Exp $
"""
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)


=== Added File Zope3/src/zope/app/file/browser/file_icon.gif ===
  <Binary-ish file>

=== Added File Zope3/src/zope/app/file/browser/file_upload.hlp ===
This screen allows to upload new file data.

=== Added File Zope3/src/zope/app/file/browser/image.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 naive file editing.

$Id: image.py,v 1.1.2.1 2004/02/20 19:39:47 philikon Exp $
"""
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


=== Added File Zope3/src/zope/app/file/browser/image_edit.pt ===
<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>


=== Added File Zope3/src/zope/app/file/browser/image_icon.gif ===
  <Binary-ish file>



More information about the Zope3-Checkins mailing list