def _prepareViews(self): views = {IBrowserRequest: [], IXMLRPCRequest: [], IHTTPRequest: [], IFTPRequest: [], None: []} type_map = {IBrowserRequest: 'Browser', IXMLRPCRequest: 'XMLRPC', IHTTPRequest: 'HTTP', IFTPRequest: 'FTP', None: 'Other'} level_map = {'generic': component.GENERIC_INTERFACE_LEVEL, 'extended': component.EXTENDED_INTERFACE_LEVEL, 'specific': component.SPECIFIC_INTERFACE_LEVEL} iface = removeAllProxies(self.context) for reg in presentation.getViews(iface): type = presentation.getPresentationType(reg.required[-1]) views[(type in views) and type or None].append(reg) sort_function = lambda x, y: cmp(x['name'], y['name']) for type, sel_views in views.items(): for level, qualifier in level_map.items(): regs = tuple(component.filterAdapterRegistrations( sel_views, iface, level=qualifier)) infos = [presentation.getViewInfoDictionary(reg) for reg in regs] infos.sort() setattr(self, level+type_map[type]+'Views', infos)
def getGenericRequiredAdapters(self): """Get adapters where this interface is required.""" # Must remove security and location proxies, so that we have access to # the API methods and class representation. iface = removeAllProxies(self.context) regs = component.getRequiredAdapters(iface) regs = tuple(component.filterAdapterRegistrations( regs, iface, level=component.GENERIC_INTERFACE_LEVEL)) return [component.getAdapterInfoDictionary(reg) for reg in regs]