I'm registering a utility which I would like to list a folder's contents so as 
to populate a drop down or multi select widget; 

problem is the utility gets called from the content type's interface/schema 
definition and there seems to be no way to pass it a context either for 
getSiteManager's lookups, or simply traversing to the desired folder and 
listing its contents. 

Naturally my example cod below doesn't work but it should shed some light on my 
(so far) unsuccessful approach..


class IGroupIds(Interface):
 """Lists a group folder's items"""

 def getGroupIds():
     """go get'em"""

class GroupIds:
 implements(IGroupIds)

 def getGroupIds(self, context):
     root = getParents(context)[-2]
     return [item for item in root['groups'].keys()]


### register it as a utility

def register_groupids_util(context, event):
 sm = getSiteManager(context)
 groupids = GroupIds()
 sm.registerUtility(groupids, IGroupIds, 'groupids')

### access it from a content type's interfaces which gets called by the form 
render

client_specified_groups = component.queryUtility(IGroupIds, 
'groupids').getGroupIds(context)


class INeedTheGroupListing(IContainer):
 groups = List(
                         value_type=Choice(  title= u'Client generated groups', 
                                                                   
values=client_specified_groups,),
                         required=True
                         )
_______________________________________________
bluebream mailing list
[email protected]
https://mail.zope.org/mailman/listinfo/bluebream

Reply via email to