[Zope-CMF] Accessing skins objects

Charlie Clark charlie at begeistert.org
Mon Feb 9 05:12:03 EST 2009


I've written a very simple view for concactenating resources such as  
CSS or Javascript files to reduce the number of http browser requests:

from Products.CMFCore.utils import getToolByName
from Products.CMFDefault.browser.utils import memoize, ViewBase

class Javascript(ViewBase):
     """Return all Javascript from the skin as a single string"""

     folder_name = 'js'
     content_type = 'application/x-javascript'

     def contents(self):
         skin_tool = getToolByName(self.context, 'portal_skins')
         layer = skin_tool.getDefaultSkin()
         skin = skin_tool.getSkinByName(layer)
         folder = getattr(skin, self.folder_name)
         obs = [str(ob) for ob in folder.objectValues()
                        if ob.meta_type == "Filesystem File"]
         return "\n".join(obs)

     def __call__(self):
         data = self.contents()
         self.request.response.setHeader("Content-Length", len(data))

While this works fine, it seems to run considerably slower (about half  
the speed) than a PythonScript that calls the relevant objects  
explicitly via getattr(context, id). I'm a bit surprised at this but  
suspect it may down to whether the file system is actually accessed or  
whether a persistent object is being called. In my browser view it is  
impossible to avoid reading in the file again as this happens the  
__str__ method of the FSFile object.

In the hope of enlightenment.

Charlie Clark
Helmholtzstr. 20
D- 40215
Tel: +49-211-938-5360
GSM: +49-178-782-6226

More information about the Zope-CMF mailing list