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

Stephan Richter srichter@cbu.edu
Fri, 1 Mar 2002 01:37:12 -0500


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

Added Files:
      Tag: srichter-OFS_Formulator-branch
	ImageData.py ImageEdit.py __init__.py browser.zcml edit.pt 
Log Message:
Okay, I am finally ready to check this stuff in:

- Reorganized the internal directory structure of every content object. For
  each content object you have now a Views directory that contains further
  directories for different protocols, such as Browser (HTML), XUL, FTP ...

  Note: None of the directories is file-type, but functionality-based. It 
        is a bad idea to create directories for a particular file type, as
        it was common in Zope 2.

- Made Folder, File and Image forms Formulator-based. This allows us now to
  create forms for new protocols. such as XUL very quickly (often just a
  few lines of code). More to Formulator when it is being checked in.

- Cleaned up most files. Almost all files should have now the correct 
  license disclaimer.

- A new object called LoadedFolder was added. LoadedFolder currently 
  provides two new functionalities to folders:
    1. Ordering. You can change the order of the objects. This idea was 
       taking from the Zope 2 product OrderedFolders.
    2. Limit. You can specify the maximal amount of items the folder is 
       allowed to store. This idea was also taken from OrderedFolders.

  Note: Due to much rearranging during this development, there are no tests
        yet written for this. This needs to be done, before we merge with
        the Zoep-3x-branch again.

- Started XUL implementation of screens.

- Fixed some bugs I found lying around.


=== Added File Zope3/lib/python/Zope/App/OFS/Image/Views/Browser/ImageData.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: ImageData.py,v 1.1.2.1 2002/03/01 06:37:11 srichter Exp $
"""

from Zope.Publisher.Browser.AttributePublisher import AttributePublisher
from Zope.PageTemplate.PageTemplateFile import PageTemplateFile

class ImageData(AttributePublisher):

    __implements__ = AttributePublisher.__implements__
    
    def __init__( self, image ):
        self._image = image


    def index(self, REQUEST=None):        
        image = self.getContext()
        if REQUEST is not None:
            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.getContext().getImageSize()[0]
        if height is None:
            height = self.getContext().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


    def getContext(self):
        return self._image


=== Added File Zope3/lib/python/Zope/App/OFS/Image/Views/Browser/ImageEdit.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.

Revision Information:
$Id: ImageEdit.py,v 1.1.2.1 2002/03/01 06:37:11 srichter Exp $
"""

from Zope.App.Formulator.Form import Form
from Zope.PageTemplate.PageTemplateFile import PageTemplateFile


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 = PageTemplateFile('edit.pt')



=== Added File Zope3/lib/python/Zope/App/OFS/Image/Views/Browser/__init__.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 1.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.
##############################################################################
"""

$Id: __init__.py,v 1.1.2.1 2002/03/01 06:37:11 srichter Exp $
"""


=== Added File Zope3/lib/python/Zope/App/OFS/Image/Views/Browser/browser.zcml ===
<zopeConfigure
   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="view"
    for="Zope.App.OFS.Image.Image.IImage."
    factory="Zope.App.OFS.Image.Views.Browser.ImageData." />

  <browser:view name="data"
    for="Zope.App.OFS.Image.Image.IImage."
    factory="Zope.App.OFS.Image.Views.Browser.ImageData." />

  <security:protectClass 
     name="Zope.App.OFS.Image.Views.Browser.ImageData."
     permission_id="Zope.View" methods="index, tag" />

  <browser:view name="edit"
    for="Zope.App.OFS.Image.Image.IImage."
    factory="Zope.App.OFS.Image.Views.Browser.ImageEdit." />

  <security:protectClass 
     name="Zope.App.OFS.Image.Views.Browser.ImageEdit."
     permission_id="Zope.View" methods="index, action" />


  <!-- Formulator directives -->

  <browser:view name="DataFieldView"
    for="Zope.App.OFS.Image.Image.IImage."
    factory="Zope.App.OFS.Image.ImageFields.DataField. Zope.App.Formulator.Widgets.Browser.FileWidget." />

  <browser:view name="ContentTypeFieldView"
    for="Zope.App.OFS.Image.Image.IImage."
    factory="Zope.App.OFS.Image.ImageFields.ContentTypeField. Zope.App.Formulator.Widgets.Browser.TextWidget." />

</zopeConfigure>


=== Added File Zope3/lib/python/Zope/App/OFS/Image/Views/Browser/edit.pt ===
<html metal:use-macro="views/standard_macros/page">
  <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="container/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="editAction" method="post" enctype="multipart/form-data">

        <table class="EditTable">      
	  <tbody>   
  
	    <tr>
	      <th class="EditAttributeName">Size</th>
	      <td class="EditAttributeValue"
          	  tal:content="here/getImageSize">
              </td>
	    </tr>
  
	    <tr tal:repeat="fieldView python:container.getFieldViews(request)">
	      <th class="EditAttributeName"
                  tal:content="python: fieldView.getContext().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>