Home Ask Login Register

Developers Planet

Your answer is one click away!

Peter February 2016

Retrieve contents of objects from Plone using Python script

I am using Plone 5. I have added a Python script and what I am trying to do is to get the objects contained in one of the folders and print them. I used context.restrictedTraverse(path) to get an object by path but it only returns <Document at path> . Does anyone have any suggestions? Thanks!


Mathias February 2016

You only traversing to the document.

Here a list of some possible methods to get the children of a folder.

>>> # List all children without security checks
>>> context.restrictedTraverse(path).objectValues()

>>> # List all ids without security checks
>>> context.restrictedTraverse(path).objectIds()

>>> # List all ids/values without security checks
>>> context.restrictedTraverse(path).contentItems()

>>> # You can use the catalog, this includes security checks and more.
>>> # This will return a catalog results (brains), not the actual object.
>>> context.restrictedTraverse(path).objectIds().getFolderContents()

For further informations please check the plone docu page: http://docs.plone.org/develop/plone/content/listing.html

Post Status

Asked in February 2016
Viewed 1,113 times
Voted 5
Answered 1 times


Leave an answer

Quote of the day: live life