Plone 4 связанные предметы назад ссылка выпуска - PullRequest
0 голосов
/ 13 мая 2011

Мне не удалось найти объект обратной ссылки для связанных элементов.

мой код:

back_rels = list(catalog.findRelations({'to_id': intids.getId(aq_base(self.context))}))

for rel in back_rels:
    ob = portal.unrestrictedTraverse(rel.from_path)

Выдает исключение при работе в ob = portal.unrestrictedTraverse (rel.from_path).

Результаты отладки:

> len(back_rels)
> 1 
> rel
> <z3c.relationfield.relation.RelationValue object at oxoA86f8f0>
> rel.from_path 
> 'new-grants-target-bioterrorism'
> rel.to_path
> '/portal/urnews/ur-gets-20-million-for-biodefense-studies'

Полагаю, проблема в том, что rel.from_path не возвращает полный путь, как rel.to_path.

У меня вопрос: как rel.from_path может вернуть полный путь и получить правильный объект в

portal.unrestrictedTraverse(rel.from_path)?

Я использую Plone 4 и использую тип контента «Ловкость».

1 Ответ

0 голосов
/ 02 октября 2011

К сожалению, вы не можете получить доступ от_объекта напрямую.В этом выпуске объясняется http://code.google.com/p/dexterity/issues/detail?id=95

Использовать from_id, в котором хранится IntId, и использовать утилиту IntIds для извлечения конкретного объекта:

from Acquisition import aq_inner
from zope.component import getUtility
from zope.intid.interfaces import IIntIds
from zope.security import checkPermission
from zc.relation.interfaces import ICatalog


def back_references(source_object, attribute_name):
    """ Return back references from source object on specified attribute_name """
    catalog = getUtility(ICatalog)
    intids = getUtility(IIntIds)
    result = []
    for rel in catalog.findRelations(
                            dict(to_id=intids.getId(aq_inner(source_object)),
                                 from_attribute=attribute_name)
                            ):
        obj = intids.queryObject(rel.from_id)
        if obj is not None and checkPermission('zope2.View', obj):
            result.append(obj)
    return result
...