[Zope3-checkins] CVS: Zope3/src/zope/app/browser/container - __init__.py:1.1.2.1 add.pt:1.1.2.1 add_confirmed.pt:1.1.2.1 adding.py:1.1.2.1 configure.zcml:1.1.2.1 contents.py:1.1.2.1 find.pt:1.1.2.1 find.py:1.1.2.1 index.pt:1.1.2.1 main.pt:1.1.2.1

Jim Fulton jim@zope.com
Mon, 23 Dec 2002 14:31:05 -0500


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

Added Files:
      Tag: NameGeddon-branch
	__init__.py add.pt add_confirmed.pt adding.py configure.zcml 
	contents.py find.pt find.py index.pt main.pt 
Log Message:
Initial renaming before debugging

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


=== Added File Zope3/src/zope/app/browser/container/add.pt ===
<html metal:use-macro="views/standard_macros/dialog">
<head>
<style metal:fill-slot="headers" type="text/css">

.Selector {
    width: 10px;
}

.TypeIcon {
    width: 20px;
}

.TypeName {
    text-align: left;
}

.TypeDescription {
    text-align: left;
    font-style: italic;
}
</style>
</head>
<body>

<div metal:fill-slot="body">
<form action="action.html" method="POST">
<table class="TypeListing" cellpadding="3">

  <caption>Add Content</caption>

    <!--
      ** addingInfo returns a sequence of mappings, containing:
      **   'id'    : the id of the addable type
      **   'title' : the title of the addable type
      **   'description'  : the description of the addable type
      -->
    <tbody tal:repeat="info view/addingInfo">

    <tr>

      <td class="Selector">
        <input type="radio" name="type_name"
               tal:attributes="value info/action; id info/action" />
      </td>

      <td class="TypeName">
        <label style="font-weight: bold;"
               tal:attributes="for info/action">
          <span tal:replace="info/title" >Folder</span>
        </label>
        <div class="TypeDescription">
          <label tal:attributes="for info/action" tal:content="info/description">
            Folders are generic containers for content, including other
            folders.
          </label>
        </div>
      </td>
    </tr>

  </tbody>

  <tbody tal:condition="nothing">

    <tr>

      <td class="Selector">
        <input type="radio" name="type_name" value="" />
               
      </td>

      <td class="TypeName">
        <img alt="Folder" src="../../ZMI/www/document_icon.gif" />
        Document
      </td>

    </tr>

    <tr>
      <td class="Selector"><br /></td>
      <td class="TypeDescription">
          Documents are simple textual content.
      </td>
    </tr>

  </tbody>

  <tr>
    <td><br/></td>
    <td>
        <input type="text" name="id" tal:condition="view/namesAccepted" />
        <input type="submit" value=" Add " />
    </td>
  </tr>

</table>
</form>
</div>
</body>
</html>


=== Added File Zope3/src/zope/app/browser/container/add_confirmed.pt ===
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!--
      metal:use-macro="presentation/standard_macros/html">
  -->
<body>

<p> Object added successfully. </p>

</body>
</html>


=== Added File Zope3/src/zope/app/browser/container/adding.py ===
##############################################################################
#
# Copyright (c) 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: adding.py,v 1.1.2.1 2002/12/23 19:31:02 jim Exp $
"""

from zope.app.interfaces.container import IAdding
from zope.app.interfaces.container import IContainerNamesContainer
from zope.publisher.browser import BrowserView
from zope.interfaces.publisher import IPublishTraverse
from zope.component \
     import getView, getService, createObject, \
            queryFactory, queryView, getAdapter
from Zope.App.PageTemplate import ViewPageTemplateFile
from zope.proxy.context import ContextMethod 
from zope.event import publish
from zope.app.event.objectevent import ObjectCreatedEvent
from zope.app.interfaces.container import IZopeContainer
from zope.proxy.context import ContextSuper

class Adding(BrowserView):

    __implements__ =  IAdding, IPublishTraverse

    menu_id = "add_content"

    ############################################################
    # Implementation methods for interface
    # IAdding.py

    def add(self, content):
        'See Zope.App.OFS.Container.IAdding.IAdding'
        container = getAdapter(self.context, IZopeContainer)
        name = container.setObject(self.contentName, content)
        return container[name]
    
    # See Zope.App.OFS.Container.Views.Browser.IAdding.IAdding
    contentName = None # usually set by Adding traverser

    def nextURL(self):
        'See Zope.App.OFS.Container.IAdding.IAdding'
        return (str(getView(self.context, "absolute_url", self.request))
                + '/@@contents.html')

    ######################################
    # from: Zope.ComponentArchitecture.IPresentation.IPresentation

    # See Zope.ComponentArchitecture.IPresentation.IPresentation
    request = None # set in BrowserView.__init__

    ######################################
    # from: Zope.ComponentArchitecture.IContextDependent.IContextDependent

    # See Zope.ComponentArchitecture.IContextDependent.IContextDependent
    context = None # set in BrowserView.__init__

    ######################################
    # from: Zope.Publisher.IPublishTraverse.IPublishTraverse

    def publishTraverse(self, request, name):
        if '=' in name:            
            view_name, content_name = name.split("=", 1)
            self.contentName = content_name

            return getView(self, view_name, request)

        view = queryView(self, name, request)
        if view is not None:
            return view

        factory = queryFactory(self.context, name)
        if factory is None:
            return ContextSuper(Adding, self).publishTraverse(request, name)

        return factory
    publishTraverse = ContextMethod(publishTraverse)
    
    #
    ############################################################

    index = ViewPageTemplateFile("add.pt")

    def addingInfo(wrapped_self):
        """Return menu data"""
        menu_service = getService(wrapped_self.context, "BrowserMenu")
        return menu_service.getMenu(wrapped_self.menu_id,
                                    wrapped_self,
                                    wrapped_self.request)
    addingInfo = ContextMethod(addingInfo)

    def action(self, type_name, id=''):
        if queryView(self, type_name, self.request) is not None:
            url = "%s=%s" % (type_name, id)
            self.request.response.redirect(url)
            return

        if not id:
            raise ValueError("You must specify an id")

        self.contentName = id
        
        content = createObject(self, type_name)
        publish(self.context, ObjectCreatedEvent(content))
        
        self.add(content)
        self.request.response.redirect(self.nextURL())

    def namesAccepted(self):
        return not IContainerNamesContainer.isImplementedBy(self.context)



=== Added File Zope3/src/zope/app/browser/container/configure.zcml ===
<zopeConfigure
   xmlns='http://namespaces.zope.org/zope'
   xmlns:browser='http://namespaces.zope.org/browser'
>

  <browser:view
      for="zope.app.interfaces.container.IReadContainer"
      permission="Zope.ManageContent" 
      factory="zope.app.browser.container.find.Find">

     <browser:page name="find.html" attribute="index" />
  </browser:view>

</zopeConfigure>


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

Revision information: $Id: contents.py,v 1.1.2.1 2002/12/23 19:31:02 jim Exp $
"""
from zope.publisher.browser import BrowserView
from Zope.App.PageTemplate import ViewPageTemplateFile
from zope.app.interfaces.container import IContainer
from zope.component \
     import queryView, getView, queryAdapter,  getAdapter
from zope.app.interfaces.dublincore import IZopeDublinCore
from zope.proxy.context.context import ContextWrapper
from zope.app.interfaces.container import IZopeContainer

class Contents(BrowserView):

    __used_for__ = IContainer

    def _extractContentInfo( self, item ):
        info = { }
        info['id'] = item[0]
        info['object'] = item[1]

        info[ 'url' ] = item[0]

        zmi_icon = queryView(item[1], 'zmi_icon', self.request)
        if zmi_icon is None:
            info['icon'] = None
        else:
            info['icon'] = zmi_icon()

        dc = queryAdapter(item[1], IZopeDublinCore)
        if dc is not None:
            title = dc.title
            if title:
                info['title'] = title

            magnitude, label = getSize(item[1])
            info['size'] = {'size':magnitude, 'label':label}
            created = dc.created
            if created is not None:
                info['created'] = formatTime(created)
            
            modified = dc.modified
            if modified is not None:
                info['modified'] = formatTime(modified)

        return info


    def removeObjects(self, ids):
        """Remove objects specified in a list of object ids"""
        container = getAdapter(self.context, IZopeContainer)
        for id in ids:
            container.__delitem__(id)

        self.request.response.redirect('@@contents.html')
        
    def listContentInfo(self):
        return map(self._extractContentInfo, self.context.items())

    contents = ViewPageTemplateFile('main.pt')
    contentsMacros = contents

    _index = ViewPageTemplateFile('index.pt')

    def index(self):
        if 'index.html' in self.context:
            self.request.response.redirect('index.html')
            return ''

        return self._index()

# Below is prime material for localization.
# We are a touchpoint that should contact the personalization
# service so that users can see datetime and decimals

def formatTime(in_date):
    format='%m/%d/%Y'
    undefined=u'N/A'
    if hasattr(in_date, 'strftime'):
       return in_date.strftime(format)
    return undefined

#SteveA recommneded that getSize return
#a tuple (magnitude, (size, text_label))
#this way we can sort things intelligibly
#that dont have sizes.  

def getSize(obj):
    try:
        size=int(obj.getSize())
    except (AttributeError, ValueError):
        return (0, u'N/A')

    result = u''
    if size < 1024:
        result = "1 KB"
    elif size > 1048576:
        result = "%0.02f MB" % (size / 1048576.0)
    else:
        result = "%d KB" % (size / 1024.0)
    return (size, result)



=== Added File Zope3/src/zope/app/browser/container/find.pt ===
<html metal:use-macro="views/standard_macros/page">
<body>
<div metal:fill-slot="body" >
<form action="@@find.html" method="GET">
<input type="text" name="ids" value="" /><br />
<input type="submit" name="find_submit" value=" Find " />
</form>
<table tal:condition="request/ids | nothing">
<tr tal:repeat="item python:view.findByIds(request['ids'])">
<td><a href="" tal:attributes="href item/url" tal:content="item/id">id</a></td>
</tr>
</table>
</div>
</body>
</html>


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

$Id: find.py,v 1.1.2.1 2002/12/23 19:31:02 jim Exp $
"""

from Zope.App.PageTemplate import ViewPageTemplateFile
from zope.app.interfaces.container.find import IFind
# XXX this needs to be looked up in a registry
from zope.app.container.find import SimpleIdFindFilter

from zope.component import getAdapter, getView

from zope.publisher.browser import BrowserView

# XXX very simple implementation right now
class Find(BrowserView):
    
    index = ViewPageTemplateFile('find.pt')
        
    def findByIds(self, ids):
        """Do a find for the ids listed in ids, which is a string.
        """
        finder = getAdapter(self.context, IFind)
        ids = ids.split()
        # if we don't have any ids listed, don't search at all
        if not ids:
            return []
        request = self.request
        result = []
        for object in finder.find([SimpleIdFindFilter(ids)]):
            id = getId(object)
            url = str(getView(object, 'absolute_url', request))
            result.append({ 'id': id, 'url': url})
        return result
    
from zope.proxy.context.context import getInnerWrapperData

# XXX get the id of an object (should be imported from somewhere)
def getId(object):
    dict = getInnerWrapperData(object)
    if dict:
        return dict.get('name')
    return None


=== Added File Zope3/src/zope/app/browser/container/index.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">

  <table  id="sortable" class="listing" summary="Content listing"
             cellpadding="2" cellspacing="0" >

    <thead> 
      <tr>
        <th>&nbsp;</th>
        <th>Name</th>
        <th>Title</th>
        <th>Created</th>
        <th>Modified</th>
      </tr>
    </thead>
  
    <tbody>
  
      <tr tal:repeat="info view/listContentInfo">
  
        <td> 
          <a href="#" 
             tal:attributes="href info/url"
             tal:content="structure info/icon|default"
             >
          </a> 
        </td>
  
	<td class="ContentTitle">
	  <a href="subfolder_id"
	     tal:attributes="href info/url"
             tal:content="info/id"
	  >ID here</a>
	</td>

        <td><span tal:content="info/title|default">&nbsp;</span></td>
        <td><span tal:content="info/created|default">&nbsp;</span></td>
        <td><span tal:content="info/modified|default">&nbsp;</span></td>
  
      </tr>
  
      <tr tal:condition="nothing">
  
	<td class="ContentIcon">
	  <img alt="Document" src="../../ZMI/www/document_icon.gif" />
	</td>
  
	<td class="ContentTitle">
	   <a href="document_id">Document Title or ID here</a>
	</td>
  
      </tr>
    </tbody>
  
  </table>
  <br />

</div>
</body>
</html>






=== Added File Zope3/src/zope/app/browser/container/main.pt ===
<html metal:use-macro="views/standard_macros/page">
<head>
<style metal:fill-slot="headers" type="text/css">
</style>
</head>
<body>
<div metal:fill-slot="body">
<div metal:define-macro="contents">
  <div>Contents <a href="+"> Add... </a> </div>

  <form name="containerContentsForm" method="get" action="." 
        tal:define="container_contents view/listContentInfo"
        tal:condition="container_contents"
        >

      <table id="sortable" class="listing" summary="Content listing"
             cellpadding="2" cellspacing="0" 
             metal:define-macro="contents_table"
             >
    
        <thead> 
          <tr>
            <th>&nbsp;</th>
            <th>Name</th>
            <th>Title</th>
            <th>Size</th>
            <th>Created</th>
            <th>Modified</th>
          </tr>
        </thead>

        <tbody>

        <metal:block tal:repeat="item container_contents">
          <tr tal:define="oddrow repeat/item/odd; url item/url"
              tal:attributes="class python:oddrow and 'even' or 'odd'" > 
            <td>
              <input type="checkbox" class="noborder" name="ids:list" id="#"
                     value="#"
                     tal:attributes="value item/id;
                                     id python: 'cb_'+item['id'];
                                     checked request/ids_checked|nothing;"/>
            </td>
            <td> 
              <a href="#" 
                 tal:attributes="href 
                                 string:${url}/@@SelectedManagementView.html"
                 tal:content="structure item/icon|default"
                 >
              </a> 
              <a href="#" 
                 tal:attributes="href 
                                 string:${url}/@@SelectedManagementView.html"
                 tal:content="item/id"
                 >foo</a> 
            </td>
            <td><span tal:content="item/title|default">&nbsp;</span></td>
            <td><span tal:content="item/size|default">&nbsp;</span></td>
            <td><span tal:define="created item/created|default"
                      tal:content="created">&nbsp;</span></td>
            <td><span tal:define="modified item/modified|default"
                      tal:content="modified">&nbsp;</span></td>
          </tr>
        </metal:block>
        </tbody> 
      </table>
      <br />

      <input type="submit" name="@@removeObjects.html:method" value="Delete"
             tal:attributes="value string:menu_delete_button"
             i18n:attributes="value" /> 

  </form>

</div>

</div>
</body>
</html>