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

Jim Fulton jim@zope.com
Wed, 25 Dec 2002 09:14:00 -0500


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

Added Files:
	__init__.py add.pt add_confirmed.pt adding.py configure.zcml 
	contents.py find.pt find.py index.pt main.pt 
Log Message:
Grand renaming:

- Renamed most files (especially python modules) to lower case.

- Moved views and interfaces into separate hierarchies within each
  project, where each top-level directory under the zope package
  is a separate project.

- Moved everything to src from lib/python.

  lib/python will eventually go away. I need access to the cvs
  repository to make this happen, however.

There are probably some bits that are broken. All tests pass
and zope runs, but I haven't tried everything. There are a number
of cleanups I'll work on tomorrow.



=== Zope3/src/zope/app/browser/container/__init__.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:14:00 2002
+++ Zope3/src/zope/app/browser/container/__init__.py	Wed Dec 25 09:12:29 2002
@@ -0,0 +1,2 @@
+#
+# This file is necessary to make this directory a package.


=== Zope3/src/zope/app/browser/container/add.pt 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:14:00 2002
+++ Zope3/src/zope/app/browser/container/add.pt	Wed Dec 25 09:12:29 2002
@@ -0,0 +1,99 @@
+<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>


=== Zope3/src/zope/app/browser/container/add_confirmed.pt 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:14:00 2002
+++ Zope3/src/zope/app/browser/container/add_confirmed.pt	Wed Dec 25 09:12:29 2002
@@ -0,0 +1,12 @@
+<!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>


=== Zope3/src/zope/app/browser/container/adding.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:14:00 2002
+++ Zope3/src/zope/app/browser/container/adding.py	Wed Dec 25 09:12:29 2002
@@ -0,0 +1,106 @@
+##############################################################################
+#
+# 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$
+"""
+from zope.app.interfaces.container import IAdding
+from zope.app.interfaces.container import IContainerNamesContainer
+from zope.app.interfaces.container import IZopeContainer
+
+from zope.app.event.objectevent import ObjectCreatedEvent
+from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
+from zope.component import \
+     getView, getService, createObject, queryFactory, queryView, getAdapter
+from zope.event import publish
+from zope.proxy.context import ContextSuper, ContextMethod
+from zope.publisher.browser import BrowserView
+from zope.publisher.interfaces import IPublishTraverse
+
+
+class Adding(BrowserView):
+
+    __implements__ =  IAdding, IPublishTraverse
+
+    menu_id = "add_content"
+
+    ############################################################
+    # Implementation methods for interface
+    # IAdding.py
+
+    def add(self, content):
+        container = getAdapter(self.context, IZopeContainer)
+        name = container.setObject(self.contentName, content)
+        return container[name]
+
+    contentName = None # usually set by Adding traverser
+
+    def nextURL(self):
+        return (str(getView(self.context, "absolute_url", self.request))
+                + '/@@contents.html')
+
+    request = None # set in BrowserView.__init__
+
+    context = None # set in BrowserView.__init__
+
+    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)


=== Zope3/src/zope/app/browser/container/configure.zcml 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:14:00 2002
+++ Zope3/src/zope/app/browser/container/configure.zcml	Wed Dec 25 09:12:29 2002
@@ -0,0 +1,26 @@
+<zopeConfigure
+   xmlns='http://namespaces.zope.org/zope'
+   xmlns:browser='http://namespaces.zope.org/browser'
+>
+   
+   <browser:view
+       for="zope.app.interfaces.container.IContentContainer"
+       name="+"  
+       factory="zope.app.browser.container.adding.Adding"
+       permission="zope.ManageContent"
+       >
+
+       <browser:page name="index.html"  template="add.pt" />
+       <browser:page name="action.html" attribute="action" />
+   
+       </browser:view>
+
+  <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>


=== Zope3/src/zope/app/browser/container/contents.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:14:00 2002
+++ Zope3/src/zope/app/browser/container/contents.py	Wed Dec 25 09:12:29 2002
@@ -0,0 +1,116 @@
+##############################################################################
+#
+# 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$
+"""
+from zope.app.interfaces.container import IContainer
+from zope.app.interfaces.container import IZopeContainer
+from zope.app.interfaces.dublincore import IZopeDublinCore
+from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
+
+from zope.component import queryView, getView, queryAdapter,  getAdapter
+from zope.proxy.context import ContextWrapper
+from zope.publisher.browser import BrowserView
+
+
+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 don't 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)


=== Zope3/src/zope/app/browser/container/find.pt 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:14:00 2002
+++ Zope3/src/zope/app/browser/container/find.pt	Wed Dec 25 09:12:29 2002
@@ -0,0 +1,15 @@
+<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>


=== Zope3/src/zope/app/browser/container/find.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:14:00 2002
+++ Zope3/src/zope/app/browser/container/find.py	Wed Dec 25 09:12:29 2002
@@ -0,0 +1,56 @@
+##############################################################################
+#
+# 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$
+"""
+
+from zope.app.interfaces.container.find import IFind
+from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
+from zope.proxy.context import getInnerWrapperData
+# 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
+
+
+# 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


=== Zope3/src/zope/app/browser/container/index.pt 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:14:00 2002
+++ Zope3/src/zope/app/browser/container/index.pt	Wed Dec 25 09:12:29 2002
@@ -0,0 +1,79 @@
+<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>
+
+
+
+


=== Zope3/src/zope/app/browser/container/main.pt 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:14:00 2002
+++ Zope3/src/zope/app/browser/container/main.pt	Wed Dec 25 09:12:29 2002
@@ -0,0 +1,83 @@
+<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>
+
+
+
+