Back to index

plone3  3.1.7
setup_talkback_tree.py
Go to the documentation of this file.
00001 ##parameters=tree_root
00002 ##title=Standard Tree
00003 ##
00004 from ZTUtils import SimpleTreeMaker
00005 from Products.CMFCore.utils import getToolByName
00006 from Products.CMFDefault.permissions import ManagePortal
00007 from Products.CMFDefault.utils import decode
00008 
00009 mtool = getToolByName(script, 'portal_membership')
00010 utool = getToolByName(script, 'portal_url')
00011 portal_url = utool()
00012 
00013 tm = SimpleTreeMaker('tb_tree')
00014 def getKids(object):
00015     return object.talkback.getReplies()
00016 tm.setChildAccess(function=getKids)
00017 
00018 tree, rows = tm.cookieTree(tree_root)
00019 rows.pop(0)
00020 
00021 is_delete_allowed = mtool.checkPermission(ManagePortal, context)
00022 
00023 items = []
00024 for row in rows:
00025     branch = row.branch()
00026     item = row.object
00027     item_icon = item.getIcon(1)
00028     item_url = item.absolute_url()
00029     items.append({'tree_colspan': tree.height - row.depth,
00030                   'tree_icon': branch and branch['img'] or '',
00031                   'tree_id': row.id,
00032                   'tree_indent': row.depth - 1,
00033                   'tree_url': branch and branch['link'] or '',
00034                   'creators': item.listCreators(),
00035                   'date': item.CreationDate(),
00036                   'delete_url': is_delete_allowed and \
00037                                 ('%s/discitem_delete' % item_url) or '',
00038                   'icon': item_icon and \
00039                           ('%s/%s' % (portal_url, item_icon)) or '',
00040                   'title': item.Title(),
00041                   'url': item_url})
00042 
00043 return decode(tuple(items), context)