What is actually the meaning of depth
in plone.api.content.find
?
plone.api.content.find() describes the depth
parameter as
depth – How far in the content tree we want to search from context
For all values of depth
but 1
find
returns also the object in the context
.
Why is plone.api.content.find()
not returning the context
object when depth == 1
but returning it when depth != 1
? Is there any parameter to control it?
Is this a bug or a feature?
To reproduce it:
>>> from plone import api
>>> from zope.component.hooks import setSite
>>> setSite(app.get('Plone'))
>>> portal = api.portal.get()
>>> top_folder = api.content.create(type='Folder', title='top_folder', container=portal)
>>> sub_folder_1 = api.content.create(type='Folder', title='sub_folder_1', container=top_folder)
>>> sub_folder_2 = api.content.create(type='Folder', title='sub_folder_2', container=top_folder)
>>> api.content.transition(obj=top_folder, transition='publish')
>>> api.content.transition(obj=sub_folder_1, transition='publish')
>>> api.content.transition(obj=sub_folder_2, transition='publish')
>>> [x.getObject().title for x in api.content.find(context=top_folder, depth=0)]
['top_folder']
>>> [x.getObject().title for x in api.content.find(context=top_folder, depth=1)]
['sub_folder_1', 'sub_folder_2']
>>> [x.getObject().title for x in api.content.find(context=top_folder, depth=2)]
['top_folder', 'sub_folder_1', 'sub_folder_2']
>>> [x.getObject().title for x in api.content.find(context=top_folder, depth=3)]
['top_folder', 'sub_folder_1', 'sub_folder_2']