Back to index

plone3  3.1.7
getFolderContents.py
Go to the documentation of this file.
00001 ## Script (Python) "getFolderContents"
00002 ##bind container=container
00003 ##bind context=context
00004 ##bind namespace=
00005 ##bind script=script
00006 ##bind subpath=traverse_subpath
00007 ##parameters=contentFilter=None,batch=False,b_size=100,full_objects=False
00008 ##title=wrapper method around to use catalog to get folder contents
00009 ##
00010 
00011 mtool = context.portal_membership
00012 cur_path = '/'.join(context.getPhysicalPath())
00013 path = {}
00014 
00015 if not contentFilter:
00016     # The form and other are what really matters
00017     contentFilter = dict(getattr(context.REQUEST, 'form',{}))
00018     contentFilter.update(dict(getattr(context.REQUEST, 'other',{})))
00019 else:
00020     contentFilter = dict(contentFilter)
00021 
00022 if not contentFilter.get('sort_on', None):
00023     contentFilter['sort_on'] = 'getObjPositionInParent'
00024 
00025 if contentFilter.get('path', None) is None:
00026     path['query'] = cur_path
00027     path['depth'] = 1
00028     contentFilter['path'] = path
00029 
00030 show_inactive = mtool.checkPermission('Access inactive portal content', context)
00031 
00032 # Evaluate in catalog context because some containers override queryCatalog
00033 # with their own unrelated method (Topics)
00034 contents = context.portal_catalog.queryCatalog(contentFilter, show_all=1,
00035                                                   show_inactive=show_inactive)
00036 
00037 if full_objects:
00038     contents = [b.getObject() for b in contents]
00039 
00040 if batch:
00041     from Products.CMFPlone import Batch
00042     b_start = context.REQUEST.get('b_start', 0)
00043     batch = Batch(contents, b_size, int(b_start), orphan=0)
00044     return batch
00045 
00046 return contents