пятница, 4 февраля 2011 г.

О использовании reference_catalog

 # Общая часть
from Products.PythonScripts.standard import html_quote
from Products.CMFCore.utils import getToolByName
request = container.REQUEST
RESPONSE =  request.RESPONSE
urltool = getToolByName(context, "portal_url")
portal = urltool.getPortalObject()
catalogtool = getToolByName(context, "portal_catalog")
lcurses = [i.getObject() for i in catalogtool.searchResults(portal_type = 'Tema')]
refCatalog = getToolByName(portal, 'reference_catalog')
uid_catalog=getToolByName(portal, 'uid_catalog')
#Пример 1
for item in lcurses:
    refs = refCatalog.getReferences(item, 'content_source')
    print item.title_or_id()+'********************'
    for i in refs:
        print i.targetUID, i.sourceUID, i.relationship
        print uid_catalog(UID=i.targetUID), uid_catalog(UID=i.sourceUID)
        a=[k.getObject().getId() for k in uid_catalog(UID=i.targetUID)][0]
        b=[k.getObject().getId() for k in uid_catalog(UID=i.sourceUID)][0]
        print a, b
    print "##############################"
#Пример 2
    for i in refs:
        print i.targetUID, i.sourceUID, i.relationship
        print refCatalog.lookupObject(i.targetUID), refCatalog.lookupObject(i.sourceUID)
        a=refCatalog.lookupObject(i.targetUID)
        b=refCatalog.lookupObject(i.sourceUID)
        print a.getId(), b.getId()

return printed

каталог 'reference_catalog' возвращает объекты со свойствами:
 sourceUID -UID объекта -источника  связи
 targetUID  -UID связанного объекта,
 relation - имя связи
метод getReferences(sourceUID, relation, targetUID) позволяет получать поднаборы связей,  настраивая параметры метода.
Поскольку возвращаться  будут UID объектов, то для получения Id нужно использовать или каталог 'uid_catalog' (1 пример), или сам каталог 'reference_catalog'(2 пример). В примере приведен код для объектов типа Thema и LearnObject, связанных между собой связью 'content_source'.
Если у объекта есть поле типа
    ReferenceField(
        name='source',
        widget=ReferenceBrowserWidget(
            label='Source',
            label_msgid='LearnCurse_label_source',
            i18n_domain='LearnCurse',
        ),
        allowed_types=('LearnObject','Document','File'),
        multiValued=1,
        relationship='content_source',
    ),
то список  связанных этим отношением объектов можно получить как self.getИмя_поля. В данном примере self.getSource() - если в классе, или context.getSource() в классе вида и в виде.

Еще ссылки

 О разработке видов к продуктам Plone
http://plone.org/documentation/manual/theme-reference/buildingblocks/skin/templates/how-to-customise-view-or-edit-on-archetypes-content-items/
http://plone.org/documentation/manual/theme-reference/buildingblocks/skin/templates/customizing-at-templates/referencemanual-all-pages
http://plone.org/documentation/manual/theme-reference/buildingblocks/skin/templates/getting-started
https://weblion.psu.edu/trac/weblion/wiki/ViewTemplates
http://plone.org/documentation/manual/developer-manual/archetypes/appendix-practicals/b-org-creating-content-types-the-plone-2.5-way/zope-3-views
http://plone.org/documentation/kb/customization-for-developers/tutorial-all-pages
http://www.pererikstrandberg.se/blog/index.cgi?page=PloneArchetypesViewTemplateModifications
http://plone.org/documentation/kb/where-is-what/tutorial-all-pages

Ссылки изучающим Plone

Некоторые полезные ссылки
Про TAL
http://plone.org.ru/docs/howto/ZPT
http://plone.org.ru/docs/howto/AdvancedZPT
http://wiki.zope.org/ZPT/TALSpecification14
http://wiki.zope.org/zope2/PageTemplates

Русскоязычные
http://plone.org.ru/books/pb/ru/
http://wiki.python.su/%D0%9A%D0%BD%D0%B8%D0%B3%D0%B8/TheDefinitiveGuideToPlone
http://62.152.35.6:15006/Plone
http://62.152.35.6:15006/Plone/docs/manual
http://python.su/
http://www.komtet.ru/info/plone

Общие руководства
http://learnplone.org/
http://plone.org/documentation/manual/plone-community-developer-documentation/
http://docs.zope.org/zope2/zope2book/index.html
http://docs.zope.org/zope2/zdgbook/index.html
http://plone.org/documentation/kb/manipulating-plone-objects-programmatically/tutorial-all-pages
https://weblion.psu.edu/trac/weblion/wiki

Всероссийский конкурс  научно-технологических проектов страница конкурса https://dm-centre.ru/sirius-konkurs-projectov Цель конкурс...