Back to index

plone3  3.1.7
styles.py
Go to the documentation of this file.
00001 from Acquisition import aq_inner
00002 from Products.PythonScripts.standard import url_quote
00003 from Products.Five.browser import BrowserView
00004 from Products.CMFCore.utils import getToolByName
00005 
00006 
00007 class StylesView(BrowserView):
00008     """ Information for style rendering. """
00009 
00010     def registry(self):
00011         return getToolByName(aq_inner(self.context), 'portal_css')
00012 
00013     def skinname(self):
00014         return self.context.getCurrentSkinName()
00015 
00016     def styles(self):
00017         registry = self.registry()
00018         registry_url = registry.absolute_url()
00019 
00020         styles = registry.getEvaluatedResources(self.context)
00021         skinname = url_quote(self.skinname())
00022         result = []
00023         for style in styles:
00024             rendering = style.getRendering()
00025             if rendering == 'link':
00026                 src = "%s/%s/%s" % (registry_url, skinname, style.getId())
00027                 data = {'rendering': rendering,
00028                         'media': style.getMedia(),
00029                         'rel': style.getRel(),
00030                         'title': style.getTitle(),
00031                         'src': src}
00032             elif rendering == 'import':
00033                 src = "%s/%s/%s" % (registry_url, skinname, style.getId())
00034                 data = {'rendering': rendering,
00035                         'media': style.getMedia(),
00036                         'src': src}
00037             elif rendering == 'inline':
00038                 content = registry.getInlineResource(style.getId(),
00039                                                      self.context)
00040                 data = {'rendering': rendering,
00041                         'media': style.getMedia(),
00042                         'content': content}
00043             else:
00044                 raise ValueError, "Unkown rendering method '%s' for style '%s'" % (rendering, style.getId())
00045             result.append(data)
00046         return result