marxin
marxin

Reputation: 3912

Plone - getting and listing objects from member folder in a view

i would like to make a view, which lists objects in specific folder (say root/Members/myname). How to do this? I dont know how to reffer to folder. Something like:

items = []
folder = getFolder('/Members/' + myname)
for i in folder:
    if isinstance(news, i):
        items.append(i.title)

Hm?

Upvotes: 1

Views: 901

Answers (2)

Martijn Pieters
Martijn Pieters

Reputation: 1121266

You can ask the catalog to list the contents of a given folder, by using the path index, with a depth limit:

from Products.CMFCore.utils import getToolByName

catalog = getToolByName(context, 'portal_catalog')
contents = catalog(path=dict(query='/root/Members/' + myname, depth=1))

See quering the catalog for more information.

Alternatively, you could traverse to the folder in question and call the getFolderContents skin method on that:

memberFolder = context.unrestrictedTraverse('/root/Members/' + myname)
contents = memberFolder.getFolderContents()

The latter does the catalog search for you.

Upvotes: 3

Giacomo Spettoli
Giacomo Spettoli

Reputation: 4496

You can do it like this:

items = [obj.Title 
           for id,obj in context['test-folder'].items()
               if isinstance(news, obj)]

More info: http://collective-docs.readthedocs.org/en/latest/content/listing.html#listing-the-folder-items-using-portal-catalog

Upvotes: 0

Related Questions