Enable several named adapters to get resources
authorThierry Florac <thierry.florac@onf.fr>
Thu, 02 Jun 2016 16:33:03 +0200
changeset 140 341044279bca
parent 139 c0a07350ec46
child 141 1fa3a734453e
Enable several named adapters to get resources
src/pyams_skin/resources.py
--- a/src/pyams_skin/resources.py	Thu Jun 02 16:29:59 2016 +0200
+++ b/src/pyams_skin/resources.py	Thu Jun 02 16:33:03 2016 +0200
@@ -22,35 +22,25 @@
 
 # import packages
 from pyams_skin import myams
-from pyams_utils.adapter import adapter_config
+from pyams_utils.adapter import adapter_config, ContextRequestViewAdapter
 from zope.interface import Interface
 
 
 @adapter_config(context=(Interface, IRequest, Interface), provides=IResources)
-class ResourcesAdapter(object):
+class ResourcesAdapter(ContextRequestViewAdapter):
     """Get context resources"""
 
-    def __init__(self, context, request, view):
-        self.context = context
-        self.request = request
-        self.view = view
-
     def get_resources(self):
         myams.need()
 
 
 @adapter_config(name='resources', context=(Interface, IRequest, Interface), provides=ITALESExtension)
-class ResourcesTalesExtension(object):
+class ResourcesTalesExtension(ContextRequestViewAdapter):
     """expression:resources TALES extension"""
 
-    def __init__(self, context, request, view):
-        self.context = context
-        self.request = request
-        self.view = view
-
     def render(self, context=None):
         if context is None:
             context = self.context
-        resources = self.request.registry.queryMultiAdapter((context, self.request, self.view), IResources)
-        if resources is not None:
-            return resources.get_resources()
+        for name, adapter in self.request.registry.getAdapters((context, self.request, self.view), IResources):
+            adapter.get_resources()
+        return ''