Back to index

plone3  3.1.7
author_find_content.py
Go to the documentation of this file.
00001 ## Script (Python) "author_find_content"
00002 ##bind container=container
00003 ##bind context=context
00004 ##bind namespace=
00005 ##bind script=script
00006 ##bind subpath=traverse_subpath
00007 ##parameters=author,limit_per_type=5
00008 ##title=Find content created by a specific author
00009 ##
00010 
00011 from Products.CMFCore.utils import getToolByName
00012 
00013 catalog = getToolByName(context, 'portal_catalog')
00014 utils = getToolByName(context, 'plone_utils')
00015 
00016 friendly_types = utils.getUserFriendlyTypes()
00017 
00018 found   = {}
00019 content = catalog.searchResults(Creator      = author,
00020                                 portal_type  = friendly_types,
00021                                 sort_on      = 'modified',
00022                                 sort_order   = 'reverse')
00023 
00024 for item in content:
00025     itemType = item.portal_type
00026 
00027     if not found.has_key(itemType):
00028         found[itemType] = []
00029     if len(found[itemType]) < limit_per_type:
00030         found[itemType].append(item)
00031 
00032 ## The end result is a dictionary of lists, where the keys are the actual
00033 ## portal types. This means they are in rather random order..
00034 
00035 types = found.keys()
00036 types.sort()
00037 
00038 results = []
00039 
00040 for t in types:
00041     results.append({'portal_type' : t, 'content_items' : found[t]})
00042 
00043 return results
00044