如何在层次结构上查找特定对象

时间:2013-03-12 14:17:04

标签: plone

我正在尝试在层次结构上获取特定对象以设置自定义索引。 我通常使用request.PARENTS

获取对象
def getHierarchyObject(obj):
    cparents = obj.request.get('PARENTS')
    for cparent in cparents:
        if cparent.Type() == u'SpecificType':
            return cparent
    return false

但是设置索引不起作用,父请求为空。 我在此链接后创建了索引: http://plone.org/products/dexterity/documentation/manual/developer-manual/advanced/catalog

我需要使用aq_parent()爬上所有级别才能找到对象?

1 个答案:

答案 0 :(得分:3)

请求中的

PARENTS是遍历到达已发布对象的对象序列。

如果您需要索引对象,则不能依赖该值,因为它们不会被发布。

而是使用他们的收购链:

from Acquisition import aq_inner, aq_chain

def getParentObject(obj, type):
    for parent in aq_chain(aq_inner(obj)):
        if parent.Type() == type:
            return parent