Back to index

plone3  3.1.7
computeRelatedItems.py
Go to the documentation of this file.
00001 ## Script (Python) "computeRelatedItems"
00002 ##bind container=container
00003 ##bind context=context
00004 ##bind namespace=
00005 ##bind script=script
00006 ##bind subpath=traverse_subpath
00007 ##parameters=
00008 ##title=find related items for an object
00009 ##
00010 
00011 from AccessControl import Unauthorized
00012 from Products.CMFPlone.utils import base_hasattr
00013 
00014 if base_hasattr(context, 'getRelatedItems'):
00015     outgoing = context.getRelatedItems()
00016     incoming = []
00017     # if you want to show up the items which point to this one, too, then use the
00018     # line below
00019     #incoming = context.getBRefs('relatesTo') 
00020     res = []
00021     mtool = context.portal_membership
00022     
00023     in_out = outgoing+incoming
00024     for d in range(len(in_out)):
00025         try:
00026             obj = in_out[d]
00027         except Unauthorized:
00028             continue
00029         if obj not in res:
00030             if mtool.checkPermission('View', obj):
00031                 res.append(obj)
00032     return res