Personal tools
You are here: Home Documentation Tutorials RichDocument: Creating content types the Plone 2.1 way Getting folder listings
Support

Get Help

Join our chat rooms or support forums if you have more specific questions.

Plone Training
Learn how to design, build, and deploy a website in Plone through one of the numerous Plone training sessions around the world.
Find Plone training…
 
Document Actions

Getting folder listings

How to list the contents of a folder in a performance-friendly way

Martin Aspeli

This tutorial will teach you how to create content types the Plone 2.1 way, using the ATContentTypes library, by following the example of RichDocument, an extension of Plone's standard Page/Document type.
Page 12 of 17.

One of the best ways of killing the performance of a Plone site is to wake up all the content objects in a folder for no good reason. The old navigation tree was legendary for this. With Plone 2.1 and ExtendedPathIndex, those days are gone.

Instead of using contentVales() (or worse, objectValues()), you should always use a catalog query to get folder contents. Thanks to ExtendedPathIndex, you can limit the depth of a query to only include direct children of a path, using the depth modifier, and you can get objects in ordered folders returned in the correct order.

If you are in custom file-system code, you can do something like:

 catalog = getToolByName(self, 'portal_catalog')
 results = catalog.searchResults(path = {'query' : '/'.join(self.getPhysicalPath()),
                                         'depth' : 1 },
                                 sort_on = 'getObjPositionInParent',
                                 )

The script getFolderContents exists to make getting folder contents in page templates and other scripts as easy as possible. RichDocument uses it in its widgets and view templates whenever it needs to iterate over its contained images and attachments. getFolderContents takes the following parameters:

contentFilter
a dict with extra parameters to pass to the query. For example, RichDocument passes contentFilter={"portal_type" : ("FileAttachment",)} to only get file attachments in widget_attachmentsmanager.
batch and b_size
Used if you are using Plone's batching macro to batch the returned results. See the folder_listing template for an example.
full_objects
Pass True to this parameter to get the actual objects returned instead of a catalog result set. This won't help you with performance, but sometimes it's unavoidable. For example, richdocument_view_preview, it is not possible to render the scaled images using catalog brains (since Zope has to find the image objects to send them to the browser anyway, this is not so much of a problem).
 
by Martin Aspeli last modified November 29, 2006 - 16:49 All content is copyright Plone Foundation and the individual contributors.

with plone 3

Posted by haktom at June 2, 2008 - 14:45
this worked for me:
results = catalog.searchResults(path = {'query' : '/'.join(self.context.getPhysicalPath()),
'depth' : 1 },
sort_on = 'getObjPositionInParent',
portal_type=['Folder'],
)

For any issues with the web site functionality, please file a ticket.

Please consult the policy on plone.org content if you want your content published on this site.

Servers and hosting by