Back to index

plone3  3.1.7
folder_contents.py
Go to the documentation of this file.
00001 ##parameters=b_start=0, key='', reverse=0, ids=(), delta=1, items_copy='', items_cut='', items_delete='', items_new='', items_paste='', items_rename='', items_up='', items_down='', items_top='', items_bottom='', items_sort=''
00002 ##
00003 from ZTUtils import Batch
00004 from ZTUtils import make_query
00005 from Products.CMFCore.utils import getToolByName
00006 from Products.CMFDefault.permissions import AddPortalContent
00007 from Products.CMFDefault.permissions import DeleteObjects
00008 from Products.CMFDefault.permissions import ListFolderContents
00009 from Products.CMFDefault.permissions import ManageProperties
00010 from Products.CMFDefault.permissions import ViewManagementScreens
00011 from Products.CMFDefault.utils import decode
00012 from Products.CMFDefault.utils import html_marshal
00013 from Products.CMFDefault.utils import Message as _
00014 
00015 mtool = getToolByName(script, 'portal_membership')
00016 utool = getToolByName(script, 'portal_url')
00017 portal_url = utool()
00018 
00019 
00020 form = context.REQUEST.form
00021 default_target = 'object/folderContents'
00022 default_kw = {'b_start': b_start, 'key': key, 'reverse': reverse}
00023 if items_copy and \
00024         context.validateItemIds(**form) and \
00025         context.folder_copy_control(**form) and \
00026         context.setRedirect(context, default_target, **default_kw):
00027     return
00028 elif items_cut and \
00029         context.validateItemIds(**form) and \
00030         context.folder_cut_control(**form) and \
00031         context.setRedirect(context, default_target, **default_kw):
00032     return
00033 elif items_delete and \
00034         context.validateItemIds(**form) and \
00035         context.folder_delete_control(**form) and \
00036         context.setRedirect(context, default_target, **default_kw):
00037     return
00038 elif items_new and \
00039         context.setRedirect(context, 'object/new'):
00040     return
00041 elif items_paste and \
00042         context.validateClipboardData(**form) and \
00043         context.folder_paste_control(**form) and \
00044         context.setRedirect(context, default_target, **default_kw):
00045     return
00046 elif items_rename and \
00047         context.validateItemIds(**form) and \
00048         context.setRedirect(context, 'object/rename_items', ids=ids,
00049                             **default_kw):
00050     return
00051 elif items_sort and \
00052         context.folder_sort_control(**form) and \
00053         context.setRedirect(context, default_target, b_start=b_start):
00054     return
00055 elif items_up and \
00056         context.validateItemIds(**form) and \
00057         context.folder_up_control(**form) and \
00058         context.setRedirect(context, default_target, **default_kw):
00059     return
00060 elif items_down and \
00061         context.validateItemIds(**form) and \
00062         context.folder_down_control(**form) and \
00063         context.setRedirect(context, default_target, **default_kw):
00064     return
00065 elif items_top and \
00066         context.validateItemIds(**form) and \
00067         context.folder_top_control(**form) and \
00068         context.setRedirect(context, default_target, **default_kw):
00069     return
00070 elif items_bottom and \
00071         context.validateItemIds(**form) and \
00072         context.folder_bottom_control(**form) and \
00073         context.setRedirect(context, default_target, **default_kw):
00074     return
00075 
00076 
00077 options = {}
00078 
00079 options['title'] = context.Title()
00080 
00081 items_manage_allowed = mtool.checkPermission(ViewManagementScreens, context)
00082 items_delete_allowed = mtool.checkPermission(DeleteObjects, context)
00083 items_add_allowed = mtool.checkPermission(AddPortalContent, context)
00084 upitems_list_allowed = mtool.checkPermission(ListFolderContents, context,
00085                                              'aq_parent')
00086 items_move_allowed = mtool.checkPermission(ManageProperties, context)
00087 
00088 up_info = {}
00089 if upitems_list_allowed:
00090     up_obj = context.aq_parent
00091     if hasattr(up_obj, 'portal_url'):
00092         up_url = up_obj.getActionInfo('object/folderContents')['url']
00093         up_info = { 'icon': '%s/UpFolder_icon.gif' % portal_url,
00094                     'id': up_obj.getId(),
00095                     'url': up_url }
00096     else:
00097         up_info = { 'icon': '',
00098                     'id': 'Root',
00099                     'url': '' }
00100 options['up_info'] = up_info
00101 
00102 target = context.getActionInfo(default_target)['url']
00103 
00104 if not key:
00105     (key, reverse) = context.getDefaultSorting()
00106     is_default = 1
00107 elif (key, reverse) == context.getDefaultSorting():
00108     is_default = 1
00109 else:
00110     is_default = 0
00111 
00112 columns = ( {'key': 'Type',
00113              'title': _(u'Type'),
00114              'width': '20',
00115              'colspan': '2'}
00116           , {'key': 'getId',
00117              'title': _(u'Name'),
00118              'width': '360',
00119              'colspan': None}
00120           , {'key': 'modified',
00121              'title': _(u'Last Modified'),
00122              'width': '180',
00123              'colspan': None}
00124           , {'key': 'position',
00125              'title': _(u'Position'),
00126              'width': '80',
00127              'colspan': None }
00128           )
00129 for column in columns:
00130     if key == column['key'] and not reverse and key != 'position':
00131         query = make_query(key=column['key'], reverse=1)
00132     else:
00133         query = make_query(key=column['key'])
00134     column['url'] = '%s?%s' % (target, query)
00135 
00136 context.filterCookie()
00137 folderfilter = context.REQUEST.get('folderfilter', '')
00138 filter = context.decodeFolderFilter(folderfilter)
00139 items = context.listFolderContents(contentFilter=filter)
00140 items = sequence.sort( items, ((key, 'cmp', reverse and 'desc' or 'asc'),) )
00141 batch_obj = Batch(items, 25, b_start, orphan=0)
00142 items = []
00143 i = 1
00144 for item in batch_obj:
00145     item_icon = item.getIcon(1)
00146     item_id = item.getId()
00147     item_position = key == 'position' and str(b_start + i) or '...'
00148     i += 1
00149     item_url = item.getActionInfo( ('object/folderContents',
00150                                     'object/view') )['url']
00151     items.append( { 'checkbox': items_manage_allowed and
00152                                 ('cb_%s' % item_id) or '',
00153                     'icon': item_icon and
00154                             ( '%s/%s' % (portal_url, item_icon) ) or '',
00155                     'id': item_id,
00156                     'modified': item.ModificationDate(),
00157                     'position': item_position,
00158                     'title': item.Title(),
00159                     'type': item.Type() or None,
00160                     'url': item_url } )
00161 navigation = context.getBatchNavigation(batch_obj, target, **default_kw)
00162 options['batch'] = { 'listColumnInfos': tuple(columns),
00163                      'listItemInfos': tuple(items),
00164                      'navigation': navigation }
00165 
00166 hidden_vars = []
00167 for name, value in html_marshal(**default_kw):
00168     hidden_vars.append( {'name': name, 'value': value} )
00169 buttons = []
00170 if items_manage_allowed:
00171     if items_add_allowed and context.allowedContentTypes():
00172         buttons.append( {'name': 'items_new', 'value': _(u'New...')} )
00173         if items:
00174             buttons.append( {'name': 'items_rename',
00175                              'value': _(u'Rename...')} )
00176     if items:
00177         buttons.append( {'name': 'items_cut', 'value': _(u'Cut')} )
00178         buttons.append( {'name': 'items_copy', 'value': _(u'Copy')} )
00179     if items_add_allowed and context.cb_dataValid():
00180         buttons.append( {'name': 'items_paste', 'value': _(u'Paste')} )
00181     if items_delete_allowed and items:
00182         buttons.append( {'name': 'items_delete', 'value': _(u'Delete')} )
00183 length = batch_obj.sequence_length
00184 is_orderable = items_move_allowed and (key == 'position') and length > 1
00185 is_sortable = items_move_allowed and not is_default
00186 deltas = range( 1, min(5, length) ) + range(5, length, 5)
00187 options['form'] = { 'action': target,
00188                     'listHiddenVarInfos': tuple(hidden_vars),
00189                     'listButtonInfos': tuple(buttons),
00190                     'listDeltas': tuple(deltas),
00191                     'is_orderable': is_orderable,
00192                     'is_sortable': is_sortable }
00193 
00194 return context.folder_contents_template(**decode(options, script))