Choose the right library when creating dynamic resources
authorThierry Florac <thierry.florac@onf.fr>
Thu, 20 Dec 2018 08:40:32 +0100
changeset 496 814c9e8b5b54
parent 495 de26128cc16c
child 497 46ebb8b63379
Choose the right library when creating dynamic resources
src/pyams_skin/resources.py
--- a/src/pyams_skin/resources.py	Mon Dec 17 14:33:36 2018 +0100
+++ b/src/pyams_skin/resources.py	Thu Dec 20 08:40:32 2018 +0100
@@ -12,7 +12,6 @@
 
 __docformat__ = 'restructuredtext'
 
-from fanstatic import get_library_registry
 from pyramid.interfaces import IRequest
 from zope.dublincore.interfaces import IZopeDublinCore
 from zope.interface import Interface
@@ -27,14 +26,6 @@
 from pyams_utils.traversing import get_parent
 from pyams_utils.url import absolute_url
 
-for library in get_library_registry().values():
-    break
-else:
-    try:
-        from pyams_skin import library
-    except ImportError:
-        from pyams_default_theme import library
-
 
 @adapter_config(context=(Interface, IRequest, Interface), provides=IResources)
 class ResourcesAdapter(ContextRequestViewAdapter):
@@ -53,9 +44,10 @@
     def resources(self):
         main_resources = self.request.registry.queryMultiAdapter((self.context, self.request, self.view), IResources)
         if main_resources is not None:
-            parent_resources = (main_resources.resources[-1],)
-            skinnable = get_parent(self.request.context, ISkinnable)
-            skin_parent = skinnable.skin_parent
+            main_resource = main_resources.resources[-1]
+            library = main_resource.library
+            parent_resources = (main_resource,)
+            skin_parent = get_parent(self.request.context, ISkinnable).skin_parent
             custom_css = skin_parent.custom_stylesheet
             if custom_css:
                 modified = IZopeDublinCore(custom_css).modified