Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Zope: CMF
Accessing skins objects
 

Index | Next | Previous | View Flat


charlie at begeistert

Feb 9, 2009, 2:12 AM


Views: 640
Permalink
Accessing skins objects

Hi,

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'

@memoize
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-Type",
self.content_type)
self.request.response.setHeader("Content-Length", len(data))
self.request.response.write(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
--
Charlie Clark
Helmholtzstr. 20
Düsseldorf
D- 40215
Tel: +49-211-938-5360
GSM: +49-178-782-6226



_______________________________________________
Zope-CMF maillist - Zope-CMF[at]lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See https://bugs.launchpad.net/zope-cmf/ for bug reports and feature requests

Subject User Time
Accessing skins objects charlie at begeistert Feb 9, 2009, 2:12 AM
    Re: Accessing skins objects tseaver at palladion Feb 9, 2009, 7:10 AM
        Re: Accessing skins objects charlie at begeistert Feb 9, 2009, 7:23 AM
    Re: Accessing skins objects tseaver at palladion Feb 9, 2009, 7:10 AM
    Re: Accessing skins objects tseaver at palladion Feb 9, 2009, 9:53 AM
        Re: Accessing skins objects charlie at begeistert Feb 10, 2009, 1:16 AM
    Re: Accessing skins objects tseaver at palladion Feb 9, 2009, 9:53 AM
    Re: Accessing skins objects charlie at begeistert Feb 10, 2009, 2:59 AM
    Re: Accessing skins objects tseaver at palladion Feb 10, 2009, 5:36 AM
        Re: Accessing skins objects charlie at begeistert Feb 10, 2009, 7:28 AM
    Re: Accessing skins objects tseaver at palladion Feb 10, 2009, 5:36 AM

  Index | Next | Previous | View Flat
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.