def find_adapters(reg): for a in reg.registeredAdapters(): if len(a.required) == 1 and IStringSubstitution.implementedBy(a.factory): yield a for base in reg.__bases__: for a in find_adapters(base): yield a
def substitutionList(self): """ returns sequence: [ {'category':categoryTitle, 'items':[{'id':subId, 'description':subDescription}, ...]), ... ] """ adapters = [a for a in getGlobalSiteManager().registeredAdapters() if len(a.required)==1 and IStringSubstitution.implementedBy(a.factory)] # rearrange into categories categories = {} for a in adapters: id = a.name cat = getattr(a.factory, 'category', _(u'Miscellaneous')) desc = getattr(a.factory, 'description', u'') categories.setdefault(cat, []).append( {'id': id, 'description': desc}) # rearrange again into a sorted list res = [] keys = categories.keys() # sort, ignoring case keys.sort(lambda a, b: cmp(a.lower(), b.lower())) for key in keys: acat = categories[key] # sort by id, ignoring case acat.sort(lambda a, b: cmp(a['id'].lower(), b['id'].lower())) res.append({'category': key, 'items': acat}) return res
def find_adapters(reg): for a in reg.registeredAdapters(): if len(a.required) == 1 and IStringSubstitution.implementedBy( a.factory): yield a for base in reg.__bases__: for a in find_adapters(base): yield a
def substitutionList(self): """ returns sequence: [ {'category':categoryTitle, 'items':[{'id':subId, 'description':subDescription}, ...]), ... ] """ adapters = [ a for a in getGlobalSiteManager().registeredAdapters() if len(a.required) == 1 and IStringSubstitution.implementedBy(a.factory) ] # rearrange into categories categories = {} for a in adapters: id = a.name cat = getattr(a.factory, 'category', _(u'Miscellaneous')) desc = getattr(a.factory, 'description', u'') categories.setdefault(cat, []).append({ 'id': id, 'description': desc }) # rearrange again into a sorted list res = [] keys = categories.keys() # sort, ignoring case keys.sort(lambda a, b: cmp(a.lower(), b.lower())) for key in keys: acat = categories[key] # sort by id, ignoring case acat.sort(lambda a, b: cmp(a['id'].lower(), b['id'].lower())) res.append({'category': key, 'items': acat}) return res