[CMF-checkins] SVN: CMF/branches/tseaver-viewification/CMFDefault/ - added folder_contents view (depends still on folder_filter_form)

Yvo Schubbe y.2006_ at wcm-solutions.de
Wed Feb 1 03:43:03 EST 2006


Log message for revision 41523:
  - added folder_contents view (depends still on folder_filter_form)

Changed:
  U   CMF/branches/tseaver-viewification/CMFDefault/browser/configure.zcml
  A   CMF/branches/tseaver-viewification/CMFDefault/browser/folderviews.py
  A   CMF/branches/tseaver-viewification/CMFDefault/browser/templates/folder_contents.pt
  U   CMF/branches/tseaver-viewification/CMFDefault/configure.zcml

-=-
Modified: CMF/branches/tseaver-viewification/CMFDefault/browser/configure.zcml
===================================================================
--- CMF/branches/tseaver-viewification/CMFDefault/browser/configure.zcml	2006-02-01 00:15:00 UTC (rev 41522)
+++ CMF/branches/tseaver-viewification/CMFDefault/browser/configure.zcml	2006-02-01 08:43:01 UTC (rev 41523)
@@ -37,7 +37,7 @@
     template="templates/content_edit.pt"
     permission="cmf.ModifyPortalContent"
     layer="cmf"
-    /> 
+    />
 
  <browser:page
     for="Products.CMFDefault.interfaces.IMutableLink"
@@ -67,6 +67,15 @@
       />
 
   <browser:page
+      for="Products.CMFCore.interfaces.IFolderish"
+      name="folder_contents"
+      class=".folderviews.FolderContentsView"
+      template="templates/folder_contents.pt"
+      permission="cmf.ListFolderContents"
+      layer="cmf"
+      />
+
+  <browser:page
       for="*"
       name="form_widget"
       template="templates/form_widgets.pt"

Added: CMF/branches/tseaver-viewification/CMFDefault/browser/folderviews.py
===================================================================
--- CMF/branches/tseaver-viewification/CMFDefault/browser/folderviews.py	2006-02-01 00:15:00 UTC (rev 41522)
+++ CMF/branches/tseaver-viewification/CMFDefault/browser/folderviews.py	2006-02-01 08:43:01 UTC (rev 41523)
@@ -0,0 +1,376 @@
+##############################################################################
+#
+# Copyright (c) 2006 Zope Corporation and Contributors. All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.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.
+#
+##############################################################################
+"""Browser views for folders.
+
+$Id$
+"""
+
+from DocumentTemplate import sequence
+from ZTUtils import make_query
+
+from Products.CMFDefault.exceptions import CopyError
+from Products.CMFDefault.exceptions import zExceptions_Unauthorized
+from Products.CMFDefault.permissions import AddPortalContent
+from Products.CMFDefault.permissions import DeleteObjects
+from Products.CMFDefault.permissions import ListFolderContents
+from Products.CMFDefault.permissions import ManageProperties
+from Products.CMFDefault.permissions import ViewManagementScreens
+from Products.CMFDefault.utils import MessageID as _
+
+from utils import BatchViewBase
+from utils import decode
+from utils import FormViewBase
+from utils import memoize
+
+
+class FolderContentsView(BatchViewBase, FormViewBase):
+
+    """Contents view for IFolderish.
+    """
+
+    _BUTTONS = ({'id': 'items_new',
+                 'title': _(u'New...'),
+                 'permissions': (ViewManagementScreens, AddPortalContent),
+                 'conditions': ('checkAllowedContentTypes',),
+                 'redirect': ('context', 'object/new')},
+                {'id': 'items_rename',
+                 'title': _(u'Rename...'),
+                 'permissions': (ViewManagementScreens, AddPortalContent),
+                 'conditions': ('checkItems', 'checkAllowedContentTypes'),
+                 'transform': ('validateItemIds',),
+                 'redirect': ('context', 'object/rename_items',
+                              'b_start, ids, key, reverse')},
+                {'id': 'items_cut',
+                 'title': _(u'Cut'),
+                 'permissions': (ViewManagementScreens,),
+                 'conditions': ('checkItems',),
+                 'transform': ('validateItemIds', 'folder_cut_control'),
+                 'redirect': ('context', 'object/folderContents',
+                              'b_start, key, reverse')},
+                {'id': 'items_copy',
+                 'title': _(u'Copy'),
+                 'permissions': (ViewManagementScreens,),
+                 'conditions': ('checkItems',),
+                 'transform': ('validateItemIds', 'folder_copy_control'),
+                 'redirect': ('context', 'object/folderContents',
+                              'b_start, key, reverse')},
+                {'id': 'items_paste',
+                 'title': _(u'Paste'),
+                 'permissions': (ViewManagementScreens, AddPortalContent),
+                 'conditions': ('checkClipboardData',),
+                 'transform': ('validateClipboardData',
+                               'folder_paste_control'),
+                 'redirect': ('context', 'object/folderContents',
+                              'b_start, key, reverse')},
+                {'id': 'items_delete',
+                 'title': _(u'Delete'),
+                 'permissions': (ViewManagementScreens, DeleteObjects),
+                 'conditions': ('checkItems',),
+                 'transform': ('validateItemIds', 'folder_delete_control'),
+                 'redirect': ('context', 'object/folderContents',
+                              'b_start, key, reverse')},
+                {'id': 'items_sort',
+                 'permissions': (ManageProperties,),
+                 'transform': ('folder_sort_control',),
+                 'redirect': ('context', 'object/folderContents', 'b_start')},
+                {'id': 'items_up',
+                 'permissions': (ManageProperties,),
+                 'transform': ('validateItemIds', 'folder_up_control'),
+                 'redirect': ('context', 'object/folderContents',
+                              'b_start, key, reverse')},
+                {'id': 'items_down',
+                 'permissions': (ManageProperties,),
+                 'transform': ('validateItemIds', 'folder_down_control'),
+                 'redirect': ('context', 'object/folderContents',
+                              'b_start, key, reverse')},
+                {'id': 'items_top',
+                 'permissions': (ManageProperties,),
+                 'transform': ('validateItemIds', 'folder_top_control'),
+                 'redirect': ('context', 'object/folderContents',
+                              'b_start, key, reverse')},
+                {'id': 'items_bottom',
+                 'permissions': (ManageProperties,),
+                 'transform': ('validateItemIds', 'folder_bottom_control'),
+                 'redirect': ('context', 'object/folderContents',
+                              'b_start, key, reverse')})
+
+    # helpers
+
+    @memoize
+    def _getSorting(self):
+        key = self.request.form.get('key', None)
+        if key:
+            return (key, self.request.form.get('reverse', 0))
+        else:
+            return self.context.getDefaultSorting()
+
+    @memoize
+    def _isDefaultSorting(self):
+        return self._getSorting() == self.context.getDefaultSorting()
+
+    @memoize
+    def _getHiddenVars(self):
+        b_start = self._getBatchStart()
+        is_default = self._isDefaultSorting()
+        (key, reverse) = is_default and ('', 0) or self._getSorting()
+        return {'b_start': b_start, 'key': key, 'reverse': reverse}
+
+    @memoize
+    def _getItems(self):
+        (key, reverse) = self._getSorting()
+        self.context.filterCookie()
+        folderfilter = self.request.get('folderfilter', '')
+        filter = self.context.decodeFolderFilter(folderfilter)
+        items = self.context.listFolderContents(contentFilter=filter)
+        return sequence.sort(items,
+                             ((key, 'cmp', reverse and 'desc' or 'asc'),))
+
+    # interface
+
+    @memoize
+    @decode
+    def up_info(self):
+        mtool = self._getTool('portal_membership')
+        allowed = mtool.checkPermission(ListFolderContents, self.context,
+                                        'aq_parent')
+        if allowed:
+            up_obj = self.context.aq_inner.aq_parent
+            if hasattr(up_obj, 'portal_url'):
+                up_url = up_obj.getActionInfo('object/folderContents')['url']
+                return {'icon': '%s/UpFolder_icon.gif' % self._getPortalURL(),
+                        'id': up_obj.getId(),
+                        'url': up_url }
+            else:
+                return {'icon': '',
+                        'id': 'Root',
+                        'url': ''}
+        else:
+            return {}
+
+    @memoize
+    def listColumnInfos(self):
+        (key, reverse) = self._getSorting()
+        columns = ( {'key': 'Type',
+                     'title': _(u'Type'),
+                     'width': '20',
+                     'colspan': '2'}
+                  , {'key': 'getId',
+                     'title': _(u'Name'),
+                     'width': '360',
+                     'colspan': None}
+                  , {'key': 'modified',
+                     'title': _(u'Last Modified'),
+                     'width': '180',
+                     'colspan': None}
+                  , {'key': 'position',
+                     'title': _(u'Position'),
+                     'width': '80',
+                     'colspan': None }
+                  )
+        for column in columns:
+            if key == column['key'] and not reverse and key != 'position':
+                query = make_query(key=column['key'], reverse=1)
+            else:
+                query = make_query(key=column['key'])
+            column['url'] = '%s?%s' % (self._getViewURL(), query)
+        return tuple(columns)
+
+    @memoize
+    @decode
+    def listItemInfos(self):
+        b_start = self._getBatchStart()
+        (key, reverse) = self._getSorting()
+        batch_obj = self._getBatchObj()
+        items_manage_allowed = self._checkPermission(ViewManagementScreens)
+
+        items = []
+        i = 1
+        for item in batch_obj:
+            item_icon = item.getIcon(1)
+            item_id = item.getId()
+            item_position = (key == 'position') and str(b_start + i) or '...'
+            i += 1
+            item_url = item.getActionInfo(('object/folderContents',
+                                           'object/view'))['url']
+            items.append({'checkbox': items_manage_allowed and
+                                      ('cb_%s' % item_id) or '',
+                          'icon': item_icon and ('%s/%s' %
+                                     (self._getPortalURL(), item_icon)) or '',
+                          'id': item_id,
+                          'modified': item.ModificationDate(),
+                          'position': item_position,
+                          'title': item.Title(),
+                          'type': item.Type() or None,
+                          'url': item_url})
+        return tuple(items)
+
+    @memoize
+    def listDeltas(self):
+        length = self._getBatchObj().sequence_length
+        deltas = range(1, min(5, length)) + range(5, length, 5)
+        return tuple(deltas)
+
+    @memoize
+    def is_orderable(self):
+        length = len(self._getBatchObj())
+        items_move_allowed = self._checkPermission(ManageProperties)
+        (key, reverse) = self._getSorting()
+        return items_move_allowed and (key == 'position') and length > 1
+
+    @memoize
+    def is_sortable(self):
+        items_move_allowed = self._checkPermission(ManageProperties)
+        return items_move_allowed and not self._isDefaultSorting()
+
+    # checkers
+
+    def checkAllowedContentTypes(self):
+        return bool(self.context.allowedContentTypes())
+
+    def checkClipboardData(self):
+        return bool(self.context.cb_dataValid())
+
+    def checkItems(self):
+        return bool(self._getItems())
+
+    # validators
+
+    def validateItemIds(self, ids=(), **kw):
+        if ids:
+            return True
+        else:
+            return False, _(u'Please select one or more items first.')
+
+    def validateClipboardData(self, **kw):
+        if self.context.cb_dataValid():
+            return True
+        else:
+            return False, _(u'Please copy or cut one or more items to paste '
+                            u'first.')
+
+    # controllers
+
+    def folder_cut_control(self, ids, **kw):
+        """Cut objects from a folder and copy to the clipboard.
+        """
+        try:
+            self.context.manage_cutObjects(ids, self.request)
+            if len(ids) == 1:
+                return True, _(u'Item cut.')
+            else:
+                return True, _(u'Items cut.')
+        except CopyError:
+            return False, _(u'CopyError: Cut failed.')
+        except zExceptions_Unauthorized:
+            return False, _(u'Unauthorized: Cut failed.')
+
+    def folder_copy_control(self, ids, **kw):
+        """Copy objects from a folder to the clipboard.
+        """
+        try:
+            self.context.manage_copyObjects(ids, self.request)
+            if len(ids) == 1:
+                return True, _(u'Item copied.')
+            else:
+                return True, _(u'Items copied.')
+        except CopyError:
+            return False, _(u'CopyError: Copy failed.')
+
+    def folder_paste_control(self, **kw):
+        """Paste objects to a folder from the clipboard.
+        """
+        try:
+            result = self.context.manage_pasteObjects(self.request['__cp'])
+            if len(result) == 1:
+                return True, _(u'Item pasted.')
+            else:
+                return True, _(u'Items pasted.')
+        except CopyError:
+            return False, _(u'CopyError: Paste failed.')
+        except zExceptions_Unauthorized:
+            return False, _(u'Unauthorized: Paste failed.')
+
+    def folder_delete_control(self, ids, **kw):
+        """Delete objects from a folder.
+        """
+        self.context.manage_delObjects(list(ids))
+        if len(ids) == 1:
+            return True, _(u'Item deleted.')
+        else:
+            return True, _(u'Items deleted.')
+
+    def folder_sort_control(self, key='position', reverse=0, **kw):
+        """Sort objects in a folder.
+        """
+        self.context.setDefaultSorting(key, reverse)
+        return True
+
+    def folder_up_control(self, ids, delta, **kw):
+        subset_ids = [ obj.getId()
+                       for obj in self.context.listFolderContents() ]
+        try:
+            attempt = self.context.moveObjectsUp(ids, delta,
+                                                 subset_ids=subset_ids)
+            if attempt == 1:
+                return True, _(u'Item moved up.')
+            elif attempt > 1:
+                return True, _(u'Items moved up.')
+            else:
+                return False, _(u'Nothing to change.')
+        except ValueError:
+            return False, _(u'ValueError: Move failed.')
+
+    def folder_down_control(self, ids, delta, **kw):
+        subset_ids = [ obj.getId()
+                       for obj in self.context.listFolderContents() ]
+        try:
+            attempt = self.context.moveObjectsDown(ids, delta,
+                                                   subset_ids=subset_ids)
+            if attempt == 1:
+                return True, _(u'Item moved down.')
+            elif attempt > 1:
+                return True, _(u'Items moved down.')
+            else:
+                return False, _(u'Nothing to change.')
+        except ValueError:
+            return False, _(u'ValueError: Move failed.')
+
+    def folder_top_control(self, ids, **kw):
+        subset_ids = [ obj.getId()
+                       for obj in self.context.listFolderContents() ]
+        try:
+            attempt = self.context.moveObjectsToTop(ids,
+                                                    subset_ids=subset_ids)
+            if attempt == 1:
+                return True, _(u'Item moved to top.')
+            elif attempt > 1:
+                return True, _(u'Items moved to top.')
+            else:
+                return False, _(u'Nothing to change.')
+        except ValueError:
+            return False, _(u'ValueError: Move failed.')
+
+    def folder_bottom_control(self, ids, **kw):
+        subset_ids = [ obj.getId()
+                       for obj in self.context.listFolderContents() ]
+        try:
+            attempt = self.context.moveObjectsToBottom(ids,
+                                                       subset_ids=subset_ids)
+            if attempt == 1:
+                return True, _(u'Item moved to bottom.')
+            elif attempt > 1:
+                return True, _(u'Items moved to bottom.')
+            else:
+                return False, _(u'Nothing to change.')
+        except ValueError:
+            return False, _(u'ValueError: Move failed.')


Property changes on: CMF/branches/tseaver-viewification/CMFDefault/browser/folderviews.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Copied: CMF/branches/tseaver-viewification/CMFDefault/browser/templates/folder_contents.pt (from rev 41515, CMF/branches/tseaver-viewification/CMFDefault/skins/zpt_generic/folder_contents_template.pt)
===================================================================
--- CMF/branches/tseaver-viewification/CMFDefault/skins/zpt_generic/folder_contents_template.pt	2006-01-31 17:47:30 UTC (rev 41515)
+++ CMF/branches/tseaver-viewification/CMFDefault/browser/templates/folder_contents.pt	2006-02-01 08:43:01 UTC (rev 41523)
@@ -0,0 +1,92 @@
+<html metal:use-macro="context/@@standard_macros/page">
+<body>
+
+<metal:slot metal:fill-slot="header" i18n:domain="cmf_default">
+<h1 i18n:translate="">Folder Contents: <tal:span
+    tal:content="view/title" i18n:name="obj_title">Title</tal:span></h1>
+</metal:slot>
+
+<metal:slot metal:fill-slot="body" i18n:domain="cmf_default">
+<p tal:define="up_info view/up_info" tal:condition="up_info"
+><tal:case tal:condition="up_info/url"
+ ><a href="" tal:attributes="href up_info/url"
+  ><img src="" alt="[Link]" border="0" tal:attributes="src up_info/icon"
+      i18n:attributes="alt" /></a>
+  <span tal:omit-tag="" i18n:translate="">Up to</span>
+  <a href="" tal:attributes="href up_info/url"
+     tal:content="up_info/id">ID</a></tal:case
+><tal:case tal:condition="not: up_info/url"
+ ><span class="mild" i18n:translate="">Root</span></tal:case></p>
+
+<form action="folder_contents" method="post"
+   tal:attributes="action view/form_action"
+><metal:macro metal:use-macro="context/@@form_widget/hidden_vars" />
+ <table class="BatchTable"
+    tal:condition="view/listItemInfos">
+  <thead>
+   <tr class="list-header">
+    <th width="80" tal:repeat="column_info view/listColumnInfos"
+       tal:attributes="width column_info/width; colspan column_info/colspan"
+    ><a href="" tal:attributes="href column_info/url"
+        tal:content="column_info/title" i18n:translate="">Type</a></th>
+   </tr>
+  </thead>
+  <tbody tal:repeat="item_info view/listItemInfos">
+   <tr class="" tal:define="even repeat/item_info/even"
+      tal:attributes="class python: (even and 'row-hilite') or 'row-normal'">
+      <td width="5"
+      ><input type="checkbox" name="ids:list" value="" id=""
+          tal:attributes="value item_info/id; id item_info/checkbox"
+          tal:condition="item_info/checkbox" /></td>
+      <td
+      ><a href="" tal:attributes="href item_info/url"
+          tal:condition="item_info/icon"
+       ><img src="" alt="" border="0"
+           tal:attributes="src item_info/icon; alt item_info/type"
+           i18n:attributes="alt" /></a></td>
+      <td
+      ><a href="" tal:attributes="href item_info/url"
+       ><tal:span tal:content="item_info/id">ID</tal:span>
+        <tal:case tal:condition="item_info/title"
+           tal:content="string:(${item_info/title})">(Title)</tal:case
+      ></a></td>
+      <td
+      ><tal:span tal:content="item_info/modified">2001</tal:span></td>
+      <td
+      ><tal:span tal:content="item_info/position">1</tal:span></td>
+   </tr>
+  </tbody>
+ </table>
+ <metal:macro metal:use-macro="context/@@batch_widget/navigation" />
+ <metal:macro metal:use-macro="context/@@form_widget/buttons" />
+<tal:case tal:condition="python: view.is_orderable() or view.is_sortable()"
+> <div class="FormButtons"
+ ><tal:case tal:condition="view/is_orderable">
+  <input type="submit" name="items_up" value="Up"
+     i18n:attributes="value" />
+  /
+  <input type="submit" name="items_down" value="Down"
+     i18n:attributes="value" />
+  by
+  <select name="delta:int">
+   <option value=""
+      tal:repeat="delta view/listDeltas"
+      tal:attributes="value delta"
+      tal:content="delta">
+   </option>
+  </select>
+  <input type="submit" name="items_top" value="Top"
+     i18n:attributes="value" />
+  <input type="submit" name="items_bottom" value="Bottom"
+     i18n:attributes="value" /></tal:case
+ ><tal:case tal:condition="view/is_sortable">
+  <input type="submit" name="items_sort" value="Set Sorting as Default"
+     i18n:attributes="value" /></tal:case
+></div>
+</tal:case></form>
+
+<div tal:replace="structure context/folder_filter_form">Filter Form Here</div>
+</metal:slot>
+
+</body>
+</html>

Modified: CMF/branches/tseaver-viewification/CMFDefault/configure.zcml
===================================================================
--- CMF/branches/tseaver-viewification/CMFDefault/configure.zcml	2006-02-01 00:15:00 UTC (rev 41522)
+++ CMF/branches/tseaver-viewification/CMFDefault/configure.zcml	2006-02-01 08:43:01 UTC (rev 41523)
@@ -13,6 +13,9 @@
     />
 
   <five:traversable
+     class="Products.CMFCore.PortalFolder.PortalFolder"
+     />
+  <five:traversable
      class="Products.CMFDefault.Document.Document"
      />
   <five:traversable 



More information about the CMF-checkins mailing list