[Zope3-checkins] CVS: Zope3/src/zope/app/browser/container - contents.pt:1.4.2.1 adding.py:1.9.12.1 contents.py:1.17.12.1 find.py:1.2.28.1 main.pt:NONE rename.pt:NONE

Grégoire Weber zope@i-con.ch
Sun, 22 Jun 2003 10:24:07 -0400


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

Modified Files:
      Tag: cw-mail-branch
	adding.py contents.py find.py 
Added Files:
      Tag: cw-mail-branch
	contents.pt 
Removed Files:
      Tag: cw-mail-branch
	main.pt rename.pt 
Log Message:
Synced up with HEAD

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

  <form name="containerContentsForm" method="POST" action="."
        tal:attributes="action request/URL"
        tal:define="container_contents view/listContentInfo"
        >

      <input type="hidden" name="type_name" value=""
             tal:attributes="value request/type_name"
             tal:condition="request/type_name|nothing"
             />
      <input type="hidden" name="retitle_id" value=""
             tal:attributes="value request/retitle_id"
             tal:condition="request/retitle_id|nothing"
             />

      <div class="page_error"
           tal:condition="view/error" 
           tal:content="view/error">
        Error message
      </div>

      <table id="sortable" class="listing" summary="Content listing">
    
        <thead> 
          <tr>
            <th>&nbsp;</th>
            <th>Name</th>
            <th>Title</th>
            <th>Size</th>
            <th>Created</th>
            <th>Modified</th>
          </tr>
        </thead>

        <tbody>

        <tr tal:condition="request/type_name|nothing">
          <td></td>
          <td><input name="new_value" id="focusid" value=""></td>
          <td></td>
          <td></td>
          <td></td>
        </tr>

        <metal:block tal:define="supportsRename view/supportsRename"
                     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 item/cb_id;
                                     checked request/ids_checked|nothing;"/>
            </td>
            <td><a href="#" 
                 tal:attributes="href 
                                 string:${url}/@@SelectedManagementView.html"
                 tal:content="structure item/icon|default">
                </a
                ><span tal:condition="item/rename"
                   ><input name="new_value:list" 
                     tal:attributes="value item/id"
                     /><input type="hidden" name="rename_ids:list" value=""
                              tal:attributes="value item/rename"
                     /></span
                ><span tal:condition="not:item/rename">
                  <a href="#" 
                     tal:attributes="href 
                                 string:${url}/@@SelectedManagementView.html"
                     tal:content="item/id"
                     >foo</a
                  ><a href="#" 
                     tal:attributes="href 
                         string:${request/URL}?rename_ids:list=${item/id}"
                     tal:condition="supportsRename"
                     >&nbsp;&nbsp;</a
                ></span
               ></td>
            <td>
              <input name="new_value" id="focusid"
                     tal:attributes="value item/title|nothing"
                     tal:condition="item/retitle"
                     />
              <a href="#" 
                 tal:attributes="href 
                                 string:${request/URL}?retitle_id=${item/id}"
                 tal:condition="item/retitleable"
                 tal:content="item/title|default"
                 >&nbsp;&nbsp;&nbsp;&nbsp;</a> 
              <span 
                 tal:condition="item/plaintitle"
                 tal:content="item/title|default"
                 >&nbsp;&nbsp;&nbsp;&nbsp;</span> 
            </td>
            <td><span tal:attributes="size item/size/sizeForSorting"
                      tal:content="item/size/sizeForDisplay">&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>

      <div tal:condition="view/normalButtons">
        <input type="submit" name="container_rename_button" value="Rename"
               i18n:attributes="value container_rename_button" 
               tal:condition="view/supportsRename"
               />
        <input type="submit" name="container_cut_button" value="Cut"
               i18n:attributes="value container_cut_button" 
               tal:condition="view/supportsCut"
               />
        <input type="submit" name="container_copy_button" value="Copy"
               i18n:attributes="value container_copy_button" 
               tal:condition="view/supportsCopy"
               />
        <input type="submit" name="container_paste_button" value="Paste"
               tal:condition="view/hasClipboardContents" 
               i18n:attributes="value container_paste_button" 
               />
        <input type="submit" name="container_delete_button" value="Delete"
               i18n:attributes="value container_delete_button"
               i18n:domain="zope"
               />
      </div>

      <div tal:condition="view/specialButtons">
        <input type="submit" value="Apply"
               i18n:attributes="value container_apply_button" 
               />
        <input type="submit" name="container_cancel_button" value="Cancel"
               i18n:attributes="value container_cancel_button" 
               />
      </div>

  </form>

      <script ><!--
          prettydump('focus', LG_INFO);
          document.containerContentsForm.new_value.focus();
          //-->
      </script>


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


=== Zope3/src/zope/app/browser/container/adding.py 1.9 => 1.9.12.1 ===
--- Zope3/src/zope/app/browser/container/adding.py:1.9	Mon Apr 28 16:42:27 2003
+++ Zope3/src/zope/app/browser/container/adding.py	Sun Jun 22 10:22:36 2003
@@ -17,6 +17,8 @@
 """
 __metaclass__ = type
 
+from zope.app import zapi
+
 from zope.app.interfaces.exceptions import UserError
 
 from zope.app.interfaces.container import IAdding
@@ -25,34 +27,30 @@
 
 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.app.event import publish
-from zope.proxy.context import ContextSuper, ContextMethod
 from zope.publisher.browser import BrowserView
 from zope.publisher.interfaces import IPublishTraverse
 
 from zope.app.i18n import ZopeMessageIDFactory as _
+from zope.interface import implements
 
-class Adding(BrowserView):
-
-    __implements__ =  IAdding, IPublishTraverse
+class BasicAdding(BrowserView):
 
-    menu_id = "add_content"
+    implements(IAdding, IPublishTraverse)
 
     ############################################################
     # Implementation methods for interface
     # IAdding.py
 
     def add(self, content):
-        container = getAdapter(self.context, IZopeContainer)
+        container = zapi.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))
+        return (str(zapi.getView(self.context, "absolute_url", self.request))
                 + '/@@contents.html')
 
     request = None # set in BrowserView.__init__
@@ -66,65 +64,75 @@
 
             if view_name.startswith('@@'):
                 view_name = view_name[2:]
-            return getView(self, view_name, request)
+            return zapi.getView(self, view_name, request)
 
         if name.startswith('@@'):
             view_name = name[2:]
         else:
             view_name = name
 
-        view = queryView(self, view_name, request)
+        view = zapi.queryView(self, view_name, request)
         if view is not None:
             return view
 
-        factory = queryFactory(self.context, name)
+        factory = zapi.queryFactory(self.context, name)
         if factory is None:
-            return ContextSuper(Adding, self).publishTraverse(request, name)
+            return zapi.ContextSuper(Adding, self).publishTraverse(
+                request, name)
 
         return factory
 
-    publishTraverse = ContextMethod(publishTraverse)
+    publishTraverse = zapi.ContextMethod(publishTraverse)
 
     #
     ############################################################
 
-    index = ViewPageTemplateFile("add.pt")
-
-    def addingInfo(wrapped_self):
-        """Return menu data.
-
-        This is sorted by title.
-        """
-        menu_service = getService(wrapped_self.context, "BrowserMenu")
-        result = menu_service.getMenu(wrapped_self.menu_id,
-                                      wrapped_self,
-                                      wrapped_self.request)
-        result.sort(lambda a, b: cmp(a['title'], b['title']))
-        return result
-    addingInfo = ContextMethod(addingInfo)
-
     def action(self, type_name='', id=''):
         if not type_name:
             raise UserError(_(u"You must select the type of object to add."))
-        
+
         if type_name.startswith('@@'):
             type_name = type_name[2:]
 
-        if queryView(self, type_name, self.request) is not None:
-            url = "%s=%s" % (type_name, id)
+        if zapi.queryView(self, type_name, self.request) is not None:
+            url = "%s/%s=%s" % (
+                zapi.getView(self, "absolute_url", self.request),
+                type_name, id)
             self.request.response.redirect(url)
             return
 
         if not id:
-            raise ValueError(_(u"You must specify an id"))
+            raise UserError(_(u"You must specify an id"))
 
         self.contentName = id
 
-        content = createObject(self, type_name)
+        content = zapi.createObject(self, type_name)
         publish(self.context, ObjectCreatedEvent(content))
 
         self.add(content)
         self.request.response.redirect(self.nextURL())
 
+    action = zapi.ContextMethod(action)
+        
+
     def namesAccepted(self):
         return not IContainerNamesContainer.isImplementedBy(self.context)
+
+class Adding(BasicAdding):
+
+    menu_id = "add_content"
+
+    index = ViewPageTemplateFile("add.pt")
+
+    def addingInfo(wrapped_self):
+        """Return menu data.
+
+        This is sorted by title.
+        """
+        menu_service = zapi.getService(wrapped_self.context, "BrowserMenu")
+        result = menu_service.getMenu(wrapped_self.menu_id,
+                                      wrapped_self,
+                                      wrapped_self.request)
+        result.sort(lambda a, b: cmp(a['title'], b['title']))
+        return result
+    addingInfo = zapi.ContextMethod(addingInfo)


=== Zope3/src/zope/app/browser/container/contents.py 1.17 => 1.17.12.1 ===
--- Zope3/src/zope/app/browser/container/contents.py:1.17	Wed Apr 30 19:37:50 2003
+++ Zope3/src/zope/app/browser/container/contents.py	Sun Jun 22 10:22:36 2003
@@ -15,43 +15,144 @@
 
 Revision information: $Id$
 """
+
+from zope.app import zapi
 from zope.app.interfaces.container import IContainer, IZopeContainer
 from zope.app.interfaces.dublincore import IZopeDublinCore
 from zope.app.interfaces.size import ISized
 from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
-
-from zope.component import queryView, queryAdapter, getAdapter, getService
 from zope.publisher.browser import BrowserView
-from zope.app.traversing import traverse, getPath, joinPath
 from zope.app.interfaces.copypastemove import IPrincipalClipboard
 from zope.app.interfaces.copypastemove import IObjectCopier
 from zope.app.interfaces.copypastemove import IObjectMover
+from zope.app.interfaces.container import IPasteTarget
+from zope.app.interfaces.container import ICopySource, IMoveSource
+from zope.app.interfaces.dublincore import IDCDescriptiveProperties
+from zope.app.i18n import ZopeMessageIDFactory as _
+
+from zope.app.browser.container.adding import BasicAdding
+
 
 class Contents(BrowserView):
 
     __used_for__ = IContainer
 
+    error = ''
+    message = ''
+    normalButtons = False
+    specialButtons = False
+    supportsRename = False
+
+    def listContentInfo(self):
+        request = self.request
+
+        if  "container_cancel_button" in request:
+            if "type_name" in request:
+                del request.form['type_name']
+            if "rename_ids" in request and "new_value" in request:
+                del request.form['rename_ids']
+            if "retitle_id" in request and "new_value" in request:
+                del request.form['retitle_id']
+
+            return self._normalListContentsInfo()
+
+        elif "container_rename_button" in request and not request.get("ids"):
+            self.error = _("You didn't specify any ids to rename.")
+
+        elif "type_name" in request and "new_value" in request:
+            self.addObject()
+        elif "rename_ids" in request and "new_value" in request:
+            self.renameObjects()
+        elif "retitle_id" in request and "new_value" in request:
+            self.changeTitle()
+        elif "container_cut_button" in request:
+            self.cutObjects()
+        elif "container_copy_button" in request:
+            self.copyObjects()
+        elif "container_paste_button" in request:
+            self.pasteObjects()
+        elif "container_delete_button" in request:
+            self.removeObjects()
+        else:
+            return self._normalListContentsInfo()
+
+        if self.error:
+            return self._normalListContentsInfo()
+
+        status = request.response.getStatus()
+        if status not in (302, 303):
+            # Only redirect if nothing else has
+            request.response.redirect(request.URL)
+        return ()
+
+    def _normalListContentsInfo(self):
+        request = self.request
+
+        self.specialButtons = (
+                 'type_name' in request or
+                 'rename_ids' in request or
+                 ('container_rename_button' in request
+                  and request.get("ids")) or
+                 'retitle_id' in request
+                 )
+        self.normalButtons = not self.specialButtons
+
+        info = map(self._extractContentInfo,
+                   zapi.getAdapter(self.context, IZopeContainer).items())
+
+        self.supportsCut = (
+            info and zapi.queryAdapter(self.context, IMoveSource) is not None)
+        self.supportsCopy = (
+            info and zapi.queryAdapter(self.context, ICopySource) is not None)
+        self.supportsPaste = (
+            zapi.queryAdapter(self.context, IPasteTarget) is not None)
+
+        self.supportsRename = self.supportsCut and self.supportsPaste
+
+        return info
+        
+
     def _extractContentInfo(self, item):
+        request = self.request
+
+
+        rename_ids = {}
+        if "container_rename_button" in request:
+            for rename_id in request.get('ids', ()):
+                rename_ids[rename_id] = rename_id
+        elif "rename_ids" in request:
+            for rename_id in request.get('rename_ids', ()):
+                rename_ids[rename_id] = rename_id
+                
+        
+        retitle_id = request.get('retitle_id')
+        
         id, obj = item
         info = {}
-        info['id'] = id
+        info['id'] = info['cb_id'] = id
         info['object'] = obj
 
         info['url'] = id
+        info['rename'] = rename_ids.get(id)
+        info['retitle'] = id == retitle_id
+        
 
-        zmi_icon = queryView(obj, 'zmi_icon', self.request)
+        zmi_icon = zapi.queryView(obj, 'zmi_icon', self.request)
         if zmi_icon is None:
             info['icon'] = None
         else:
             info['icon'] = zmi_icon()
 
-        dc = queryAdapter(obj, IZopeDublinCore)
+        dc = zapi.queryAdapter(obj, IZopeDublinCore)
         if dc is not None:
+            info['retitleable'] = id != retitle_id
+            info['plaintitle'] = 0
+            
             title = dc.title
             if title:
                 info['title'] = title
 
-            formatter = self.request.locale.getDateFormatter('medium')
+            formatter = self.request.locale.getDateTimeFormatter('short')
             created = dc.created
             if created is not None:
                 info['created'] = formatter.format(created)
@@ -59,107 +160,149 @@
             modified = dc.modified
             if modified is not None:
                 info['modified'] = formatter.format(modified)
+        else:
+            info['retitleable'] = 0
+            info['plaintitle'] = 1
 
-        sized_adapter = queryAdapter(obj, ISized)
+
+        sized_adapter = zapi.queryAdapter(obj, ISized)
         if sized_adapter is not None:
             info['size'] = sized_adapter
         return info
 
-    def renameObjects(self, ids, newids):
+    def renameObjects(self):
         """Given a sequence of tuples of old, new ids we rename"""
-        container = getAdapter(self.context, IZopeContainer)
-        for id, newid in zip(ids, newids):
+        request = self.request
+        ids = request.get("rename_ids")
+        newids = request.get("new_value")
+
+        for id, newid in map(None, ids, newids):
             if newid != id:
+                container = zapi.getAdapter(self.context, IZopeContainer)
                 container.rename(id, newid)
-        self.request.response.redirect('@@contents.html')
 
-    def removeObjects(self, ids):
+    def changeTitle(self):
+        """Given a sequence of tuples of old, new ids we rename"""
+        request = self.request
+        id = request.get("retitle_id")
+        new = request.get("new_value")
+
+        item = self.context[id]
+        dc = zapi.getAdapter(item, IDCDescriptiveProperties)
+        dc.title = new
+
+    def addObject(self):
+        request = self.request
+        new = request["new_value"]
+        if new:
+            adding = zapi.queryView(self.context, "+", request)
+            if adding is None:
+                adding = BasicAdding(self.context, request)
+            else:
+                # Set up context so that the adding can build a url
+                # if the type name names a view.
+                # Note that we can't so this for the "adding is None" case
+                # above, because there is no "+" view.
+                adding = zapi.ContextWrapper(adding, self.context, name="+")
+
+            adding.action(request['type_name'], new)
+
+            
+
+            
+    def removeObjects(self):
         """Remove objects specified in a list of object ids"""
-        container = getAdapter(self.context, IZopeContainer)
+        request = self.request
+        ids = request.get('ids')
+        if not ids:
+            self.error = _("You didn't specify any ids to remove.")
+            return
+                 
+        container = zapi.getAdapter(self.context, IZopeContainer)
         for id in ids:
             container.__delitem__(id)
 
-        self.request.response.redirect('@@contents.html')
-
-    def copyObjects(self, ids):
+    def copyObjects(self):
         """Copy objects specified in a list of object ids"""
-        container_path = getPath(self.context)
+        request = self.request
+        ids = request.get('ids')
+        if not ids:
+            self.error = _("You didn't specify any ids to copy.")
+            return
+                 
+        container_path = zapi.getPath(self.context)
 
         user = self.request.user
-        annotationsvc = getService(self.context, 'PrincipalAnnotation')
-        annotations = annotationsvc.getAnnotation(user)
-        clipboard = getAdapter(annotations, IPrincipalClipboard)
+        annotationsvc = zapi.getService(self.context, 'PrincipalAnnotation')
+        annotations = annotationsvc.getAnnotations(user)
+        clipboard = zapi.getAdapter(annotations, IPrincipalClipboard)
         clipboard.clearContents()
         items = []
         for id in ids:
-            items.append(joinPath(container_path, id))
+            items.append(zapi.joinPath(container_path, id))
         clipboard.addItems('copy', items)
 
-        self.request.response.redirect('@@contents.html')
-
-    def cutObjects(self, ids):
+    def cutObjects(self):
         """move objects specified in a list of object ids"""
-        container_path = getPath(self.context)
+        request = self.request
+        ids = request.get('ids')
+        if not ids:
+            self.error = _("You didn't specify any ids to cut.")
+            return
+
+        container_path = zapi.getPath(self.context)
 
         user = self.request.user
-        annotationsvc = getService(self.context, 'PrincipalAnnotation')
-        annotations = annotationsvc.getAnnotation(user)
-        clipboard = getAdapter(annotations, IPrincipalClipboard)
+        annotationsvc = zapi.getService(self.context, 'PrincipalAnnotation')
+        annotations = annotationsvc.getAnnotations(user)
+        clipboard = zapi.getAdapter(annotations, IPrincipalClipboard)
         clipboard.clearContents()
         items = []
         for id in ids:
-            items.append(joinPath(container_path, id))
+            items.append(zapi.joinPath(container_path, id))
         clipboard.addItems('cut', items)
 
-        self.request.response.redirect('@@contents.html')
-
     def pasteObjects(self):
         """Iterate over clipboard contents and perform the
            move/copy operations"""
         target = self.context
 
         user = self.request.user
-        annotationsvc = getService(self.context, 'PrincipalAnnotation')
-        annotations = annotationsvc.getAnnotation(user)
-        clipboard = getAdapter(annotations, IPrincipalClipboard)
+        annotationsvc = zapi.getService(self.context, 'PrincipalAnnotation')
+        annotations = annotationsvc.getAnnotations(user)
+        clipboard = zapi.getAdapter(annotations, IPrincipalClipboard)
         items = clipboard.getContents()
         for item in items:
-            obj = traverse(target, item['target'])
+            obj = zapi.traverse(target, item['target'])
             if item['action'] == 'cut':
-                getAdapter(obj, IObjectMover).moveTo(target)
-                # XXX need to remove the item from the clipboard here
-                # as it will not be available anymore from the old location
+                zapi.getAdapter(obj, IObjectMover).moveTo(target)
+                clipboard.clearContents()
             elif item['action'] == 'copy':
-                getAdapter(obj, IObjectCopier).copyTo(target)
+                zapi.getAdapter(obj, IObjectCopier).copyTo(target)
             else:
                 raise
 
-        self.request.response.redirect('@@contents.html')
-
     def hasClipboardContents(self):
         """ interogates the PrinicipalAnnotation to see if
            clipboard contents exist """
 
+        if not self.supportsPaste:
+            return False
+
         user = self.request.user
 
-        annotationsvc = getService(self.context, 'PrincipalAnnotation')
-        annotations = annotationsvc.getAnnotation(user)
-        clipboard = getAdapter(annotations, IPrincipalClipboard)
+        annotationsvc = zapi.getService(self.context, 'PrincipalAnnotation')
+        annotations = annotationsvc.getAnnotations(user)
+        
+        clipboard = zapi.getAdapter(annotations, IPrincipalClipboard)
 
         if clipboard.getContents():
             return True
 
         return False
 
-
-    def listContentInfo(self):
-        return map(self._extractContentInfo,
-                   getAdapter(self.context, IZopeContainer).items())
-
-    contents = ViewPageTemplateFile('main.pt')
+    contents = ViewPageTemplateFile('contents.pt')
     contentsMacros = contents
-
-    rename = ViewPageTemplateFile('rename.pt')
 
     _index = ViewPageTemplateFile('index.pt')
 


=== Zope3/src/zope/app/browser/container/find.py 1.2 => 1.2.28.1 ===
--- Zope3/src/zope/app/browser/container/find.py:1.2	Wed Dec 25 09:12:29 2002
+++ Zope3/src/zope/app/browser/container/find.py	Sun Jun 22 10:22:36 2003
@@ -18,7 +18,7 @@
 
 from zope.app.interfaces.container.find import IFind
 from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
-from zope.proxy.context import getInnerWrapperData
+from zope.context import getInnerWrapperData
 # XXX this needs to be looked up in a registry
 from zope.app.container.find import SimpleIdFindFilter
 

=== Removed File Zope3/src/zope/app/browser/container/main.pt ===

=== Removed File Zope3/src/zope/app/browser/container/rename.pt ===