Back to index

plone3  3.1.7
scripts.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 ScriptsView(BrowserView):
00008     """ Information for script rendering. """
00009 
00010     def registry(self):
00011         return getToolByName(aq_inner(self.context), 'portal_javascripts')
00012 
00013     def skinname(self):
00014         return self.context.getCurrentSkinName()
00015 
00016     def scripts(self):
00017         registry = self.registry()
00018         registry_url = registry.absolute_url()
00019 
00020         scripts = registry.getEvaluatedResources(self.context)
00021         skinname = url_quote(self.skinname())
00022         result = []
00023         for script in scripts:
00024             inline = bool(script.getInline())
00025             if inline:
00026                 content = registry.getInlineResource(script.getId(),
00027                                                      self.context)
00028                 data = {'inline': inline,
00029                         'content': content}
00030             else:
00031                 src = "%s/%s/%s" % (registry_url, skinname, script.getId())
00032                 data = {'inline': inline,
00033                         'src': src}
00034             result.append(data)
00035         return result