[CMF-checkins] CVS: CMF/CMFDefault/skins/zpt_generic - folder_contents_control.py:1.1 folder_contents.pt:1.11

Yvo Schubbe schubbe at web.de
Wed Jan 7 12:22:36 EST 2004


Update of /cvs-repository/CMF/CMFDefault/skins/zpt_generic
In directory cvs.zope.org:/tmp/cvs-serv31932/CMFDefault/skins/zpt_generic

Modified Files:
	folder_contents.pt 
Added Files:
	folder_contents_control.py 
Log Message:
- replaced 4 scripts and some tal code by a controller script (the scripts are still there for backwards compatibility / dtml skins)
- removed some nested tables
- catches now more exceptions
- uses now actions for redirects
- some more cleanup and refactoring


=== Added File CMF/CMFDefault/skins/zpt_generic/folder_contents_control.py ===
## Script (Python) "folder_contents_control"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=ids=(), b_start=0, items_copy='', items_cut='', items_delete='', items_new='', items_paste='', items_rename='', **kw
##title=
##
from ZTUtils import Batch
from ZTUtils import make_query
from Products.CMFCore.CMFCoreExceptions import CopyError
from Products.CMFCore.CMFCoreExceptions import zExceptions_Unauthorized
from Products.CMFCore.CMFCorePermissions import AddPortalContent
from Products.CMFCore.CMFCorePermissions import DeleteObjects
from Products.CMFCore.CMFCorePermissions import ListFolderContents
from Products.CMFCore.CMFCorePermissions import ViewManagementScreens
from Products.CMFCore.utils import getToolByName
atool = getToolByName(script, 'portal_actions')
mtool = getToolByName(script, 'portal_membership')
utool = getToolByName(script, 'portal_url')
portal_url = utool()
message = ''


if not mtool.checkPermission(ListFolderContents, context):
    ti = context.getTypeInfo()
    target = ti.getActionInfo('folder/view', context)['url']
    context.REQUEST.RESPONSE.redirect(target)
    return None


if items_copy:
    if ids:
        context.manage_copyObjects(ids, context.REQUEST)
        message = 'Item%s copied.' % ( len(ids) != 1 and 's' or '' )
    else:
        message = 'Please select one or more items to copy first.'

elif items_cut:
    if ids:
        context.manage_cutObjects(ids, context.REQUEST)
        message = 'Item%s cut.' % ( len(ids) != 1 and 's' or '' )
    else:
        message = 'Please select one or more items to cut first.'

elif items_delete:
    if ids:
        context.manage_delObjects( list(ids) )
        message = 'Item%s deleted.' % ( len(ids) != 1 and 's' or '' )
    else:
        message = 'Please select one or more items to delete first.'

elif items_new:
    ti = context.getTypeInfo()
    target = ti.getActionInfo('folder/new', context)['url']
    context.REQUEST.RESPONSE.redirect(target)
    return None

elif items_paste:
    if context.cb_dataValid:
        try:
            result = context.manage_pasteObjects(context.REQUEST['__cp'])
            message = 'Item%s pasted.' % ( len(result) != 1 and 's' or '' )
        except CopyError:
            message = 'CopyError: Paste failed.'
        except zExceptions_Unauthorized:
            message = 'Unauthorized: Paste failed.'
    else:
        message = 'Please copy or cut one or more items to paste first.'

elif items_rename:
    if ids:
        ti = context.getTypeInfo()
        target = ti.getActionInfo('redirect/rename_items', context)['url']
        query = make_query( ids=list(ids) )
        context.REQUEST.RESPONSE.redirect( '%s?%s' % (target, query) )
        return None
    else:
        message = 'Please select one or more items to rename first.'

if message:
    context.REQUEST.set('portal_status_message', message)


control = {}

items_manage_allowed = mtool.checkPermission(ViewManagementScreens, context)
items_delete_allowed = mtool.checkPermission(DeleteObjects, context)
items_add_allowed = mtool.checkPermission(AddPortalContent, context)
upitems_list_allowed = mtool.checkPermission(ListFolderContents, context,
                                             'aq_parent')

up = {}
if upitems_list_allowed:
    up_obj = context.aq_parent
    if hasattr(up_obj, 'portal_url'):
        up_url = atool.getActionInfo('folder/folderContents', up_obj)['url']
        up = { 'icon': '%s/UpFolder_icon.gif' % portal_url,
               'id': up_obj.getId(),
               'url': up_url }
    else:
        up = { 'icon': '',
               'id': 'Root',
               'url': '' }
control['up'] = up

target = atool.getActionInfo('folder/folderContents', context)['url']
context.filterCookie()
folderfilter = context.REQUEST.get('folderfilter', '')
filter = context.decodeFolderFilter(folderfilter)
items = context.listFolderContents(contentFilter=filter)
batch_obj = Batch(items, 40, b_start, orphan=0)
items = []
for item in batch_obj:
    item_icon = item.getIcon(1)
    item_id = item.getId()
    if item.isPrincipiaFolderish:
        item_url = atool.getActionInfo('folder/folderContents', item)['url']
    else:
        ti = item.getTypeInfo()
        item_url = ti.getActionInfo('object/view', item)['url']
    items.append( { 'checkbox': items_manage_allowed and
                                ('cb_%s' % item_id) or '',
                    'icon': item_icon and
                            ( '%s/%s' % (portal_url, item_icon) ) or '',
                    'id': item_id,
                    'title': item.Title(),
                    'type': item.Type() or None,
                    'url': item_url } )
navigation = context.getBatchNavigation(batch_obj, target)
control['batch'] = { 'listItemInfos1': tuple(items[:20]),
                     'listItemInfos2': tuple(items[20:]),
                     'navigation': navigation }

buttons = []
if items_manage_allowed:
    if items_add_allowed and context.allowedContentTypes():
        buttons.append( {'name': 'items_new', 'value': 'New...'} )
        if items:
            buttons.append( {'name': 'items_rename', 'value': 'Rename'} )
    if items:
        buttons.append( {'name': 'items_cut', 'value': 'Cut'} )
        buttons.append( {'name': 'items_copy', 'value': 'Copy'} )
    if items_add_allowed and context.cb_dataValid():
        buttons.append( {'name': 'items_paste', 'value': 'Paste'} )
    if items_delete_allowed and items:
        buttons.append( {'name': 'items_delete', 'value': 'Delete'} )
control['form'] = { 'action': target,
                    'listButtonInfos': tuple(buttons) }

return control


=== CMF/CMFDefault/skins/zpt_generic/folder_contents.pt 1.10 => 1.11 ===
--- CMF/CMFDefault/skins/zpt_generic/folder_contents.pt:1.10	Sun Nov  2 09:30:38 2003
+++ CMF/CMFDefault/skins/zpt_generic/folder_contents.pt	Wed Jan  7 12:22:36 2004
@@ -1,217 +1,85 @@
-<tal:x define="dummy here/filterCookie;"/>
-<html xmlns:tal="http://xml.zope.org/namespaces/tal"
-      xmlns:metal="http://xml.zope.org/namespaces/metal"
-      metal:use-macro="here/main_template/macros/master"
->
+<tal:page
+   xmlns:tal="http://xml.zope.org/namespaces/tal"
+   xmlns:metal="http://xml.zope.org/namespaces/metal"
+   xmlns:i18n="http://xml.zope.org/namespaces/i18n"
+   tal:define="control python: here.folder_contents_control(**request.form)"
+   tal:condition="control"
+><html metal:use-macro="here/main_template/macros/master">
 <body>
-<div metal:fill-slot="main"
-     tal:define="m_tool here/portal_membership;
-                 checkPerm nocall: m_tool/checkPermission;
-                 list_here python:checkPerm('List folder contents', here);
-                 list_parent python:checkPerm( 'List folder contents', here
-                                             , 'aq_parent' );
-                "
-     i18n:domain="cmf_default"
->
-<div tal:condition="not: list_here"
-      tal:define="response request/RESPONSE;
-                  url here/absolute_url;
-                 "
- >
-  <span tal:define="redirect python: response.redirect( url )"></span>
-</div>
 
-<!-- This is the desktop area -->
+<metal:block metal:fill-slot="main" i18n:domain="cmf_default"
+   tal:define="batch control/batch;
+               form control/form;
+               up control/up">
 <div class="Desktop">
 
 <h1 i18n:translate="">Desktop</h1>
 
-<form action="" method="post"
-      tal:attributes="action here/absolute_url">
- <table class="FormLayout">
+<tal:case tal:condition="up"
+><tal:case tal:condition="up/url"
+ ><a href="" tal:attributes="href up/url"
+  ><img src="" alt="[Link]" border="0" tal:attributes="src up/icon"
+      i18n:attributes="alt" /></a>
+  <tal:span i18n:translate="">Up to</tal:span>
+  <a href="" tal:attributes="href up/url" tal:content="up/id">ID</a></tal:case
+><tal:case tal:condition="not: up/url"
+ ><span class="mild" i18n:translate="">Root</span></tal:case></tal:case>
+
+<form action="folder_contents" method="post"
+   tal:attributes="action control/form/action">
+ <table class="ContentsList" tal:condition="batch/listItemInfos1">
   <tr>
-   <td valign="top">
-    <table class="ContentsList">
-     <!-- Navigate to parent -->
-     <tbody tal:condition="list_parent">
-      <tr valign="top"
-          tal:define="upNav python: hasattr(here.aq_parent, 'portal_url');
-                      upID python: here.aq_parent.getId()">
-        <td colspan="3" align="left">
-         <span tal:condition="upNav | nothing">
-          <a href="../folder_contents"
-          ><img src="" alt="[Link]" border="0"
-                tal:attributes="src string:${here/portal_url}/UpFolder_icon.gif"
-          /></a>
-         </span>&nbsp;&nbsp;
-         <span tal:condition="upNav">
-          <span tal:omit-tag="" i18n:translate="">Up to</span>
-          <a href="../folder_contents"
-                   tal:content="upID">Up ID</a>
-         </span>
-         <span tal:condition="python: not(upNav)">
-           <span class="mild" i18n:translate="">Root</span>
-         </span>
-        </td>
-      </tr>
-     </tbody>
-     <!-- This row holds the "two column list" -->
-     <tr tal:define="global b_start string:0;
-                     b_start request/b_start | b_start;
-                     filterString python: request.get('folderfilter', '');
-                     filter python: here.decodeFolderFilter(filterString);
-                     items python: here.listFolderContents(
-                                                contentFilter=filter);
-                     Batch nocall: modules/ZTUtils/Batch;
-                     global batch1 python:Batch( items, 20, int(b_start)
-                                              , orphan=0);
-                     global batch2 batch1/next;
-                    "
-     >
-      <!-- First column, first half batch in 'batch1'. -->
-      <td colspan="1" align="left" width="49%">
-       <table>
-        <tr valign="top" tal:repeat="item batch1">
-         <td width="5"
-             tal:define="folderish item/isPrincipiaFolderish;
-                         portalish item/isPortalContent | nothing;
-                         global methodID python:( folderish
-                                              and 'folder_contents'
-                                               or (portalish and 'view' or '')
-                                                );
-                         global icon item/getIcon | item/icon | nothing
-                        ">
-            <input type="checkbox" name="ids:list" value="" id=""
-                   tal:attributes="value item/getId;
-                                   id python: 'cb_' + item.getId()" />
-         </td>
-         <td>
-          <span tal:condition="icon">
-           <a href=""
-              tal:attributes="href string:${item/getId}/${methodID};
-                             "
-           ><img src="" alt="" border="0"
-                 tal:attributes="src string:${here/portal_url}/${icon};
-                                 alt item/Type|nothing;"
-                 i18n:attributes="alt" /></a>
-          </span>
-         </td>
-         <td>
-          <a href=""
-             tal:attributes="href string:${item/getId}/${methodID};
-                            "
-          ><span tal:replace="item/getId">ID</span>
-           <span tal:condition="item/Title"
-                 tal:replace="string:(${item/Title})">(Title)</span></a>
-         </td>
-        </tr>
-       </table>
-      </td>
-      <!-- Spacer column. -->
-      <td width="2%">&nbsp;</td>
-      <!-- Second column, second half batch in 'batch2'. -->
-      <td colspan="1" width="49%">
-       <table>
-        <tr valign="top" tal:repeat="item batch2">
-         <td width="5"
-             tal:define="folderish item/isPrincipiaFolderish;
-                         portalish item/isPortalContent | nothing;
-                         global methodID python:( folderish
-                                              and 'folder_contents'
-                                               or (portalish and 'view' or '')
-                                                );
-                         global icon item/getIcon | item/icon | nothing
-                        ">
-            <input type="checkbox" name="ids:list" value="" id=""
-                   tal:attributes="value item/getId;
-                                   id python: 'cb_' + item.getId()" />
-         </td>
-         <td>
-          <span tal:condition="icon">
-           <a href=""
-              tal:attributes="href string:${item/getId}/${methodID};
-                             "
-           ><img src="" alt="" border="0"
-                 tal:attributes="src string:${here/portal_url}/${icon};
-                                 alt item/Type|nothing;"
-                 i18n:attributes="alt" /></a>
-          </span>
-         </td>
-         <td>
-          <a href=""
-             tal:attributes="href string:${item/getId}/${methodID};
-                            "
-          ><span tal:replace="item/getId">ID</span>
-           <span tal:condition="item/Title"
-                 tal:replace="string:(${item/Title})">(Title)</span></a>
-         </td>
-        </tr>
-       </table>
-      </td>
-
+   <td width="49%">
+    <table>
+     <tr tal:repeat="item batch/listItemInfos1">
+      <td width="5"
+      ><input type="checkbox" name="ids:tuple" value="" id=""
+          tal:attributes="value item/id; id item/checkbox"
+          tal:condition="item/checkbox" /></td>
+      <td
+      ><a href="" tal:attributes="href item/url" tal:condition="item/icon"
+       ><img src="" alt="" border="0"
+           tal:attributes="src item/icon; alt item/type"
+           i18n:attributes="alt" /></a></td>
+      <td
+      ><a href="" tal:attributes="href item/url"
+       ><tal:span tal:content="item/id">ID</tal:span>
+        <tal:case tal:condition="item/title"
+           tal:content="string:(${item/title})">(Title)</tal:case></a></td>
      </tr>
-
-     <tr>
-      <td align="left">
-       <span tal:define="p batch1/previous" tal:condition="p">
-        <a href=""
-           tal:attributes="
-                href string:folder_contents?b_start=${p/previous/first}"
-           i18n:translate=""
-        >Previous Items</a>
-       </span>
-      </td>
-      <td>&nbsp;</td>
-      <td align="right">
-       <span tal:define="n batch2/next | nothing" tal:condition="n">
-        <a href=""
-           tal:attributes="
-                href string:folder_contents?b_start=${batch2/end}"
-           i18n:translate=""
-        >Next Items</a>
-       </span>
-      </td>
-     </tr>
-    <!-- end contentList -->
     </table>
-
-    <table border="0" cellspacing="0" cellpadding="2">
-     <tr>
-      <td align="left" valign="top" width="16"></td>
-      <td align="left" valign="top">
-      <span tal:condition="python: checkPerm('Add portal content', here)
-                                   and here.allowedContentTypes()">
-        <input type="submit" name="folder_factories:method" value="New..."
-               i18n:attributes="value" />
-      </span>
-      <span tal:condition="python: checkPerm('View management screens', here)">
-        <input type="submit" name="folder_rename_form:method" value="Rename"
-               i18n:attributes="value" />
-        <input type="submit" name="folder_cut:method" value="Cut"
-               i18n:attributes="value" />
-        <input type="submit" name="folder_copy:method" value="Copy"
-               i18n:attributes="value" />
-        <span tal:condition="here/cb_dataValid">
-        <input type="submit" name="folder_paste:method" value="Paste"
-               i18n:attributes="value" />
-        </span>
-      </span>
-      <span tal:condition="python: checkPerm('Delete objects', here)">
-        <input type="submit" name="folder_delete:method" value="Delete"
-               i18n:attributes="value" />
-      </span>
-      </td>
+   </td>
+   <td width="2%">&nbsp;</td>
+   <td width="49%" tal:condition="batch/listItemInfos2">
+    <table>
+     <tr tal:repeat="item batch/listItemInfos2">
+      <td width="5"
+      ><input type="checkbox" name="ids:tuple" value="" id=""
+          tal:attributes="value item/id; id item/checkbox"
+          tal:condition="item/checkbox" /></td>
+      <td
+      ><a href="" tal:attributes="href item/url" tal:condition="item/icon"
+       ><img src="" alt="" border="0"
+           tal:attributes="src item/icon; alt item/type"
+           i18n:attributes="alt" /></a></td>
+      <td
+      ><a href="" tal:attributes="href item/url"
+       ><tal:span tal:content="item/id">ID</tal:span>
+        <tal:case tal:condition="item/title"
+           tal:content="string:(${item/title})">(Title)</tal:case></a></td>
      </tr>
     </table>
-
    </td>
   </tr>
  </table>
+ <metal:block metal:use-macro="here/batch_widgets/macros/navigation" />
+ <metal:block metal:use-macro="here/form_widgets/macros/buttons" />
 </form>
 
 <div tal:replace="structure here/folder_filter_form">Filter Form Here</div>
 
 </div>
-</div>
+</metal:block>
+
 </body>
-</html>
+</html></tal:page>




More information about the CMF-checkins mailing list