def test_override_rewrite_links(self):
        req = self.layer['request']
        req.environ['PATH_INFO'] = '++plone++foo/bar.css'
        mng = OverrideFolderManager(self.portal)
        css = """
.foo {
    background-image: url("%(site_url)s/foobar.css");
}
.bar {
    background-image: url("%(site_url)s/++plone++foo/bar/foobar.css");
}
.foobar {
    background-image: url("%(site_url)s/foo/bar/foobar.css");
}""" % {
            'site_url': self.portal.absolute_url()
        }
        mng.save_file('foo/bar.css', css)
        value = self.portal.restrictedTraverse('++plone++foo/bar.css')
        match = """
.foo {
    background-image: url("../foobar.css");
}
.bar {
    background-image: url("bar/foobar.css");
}
.foobar {
    background-image: url("../foo/bar/foobar.css");
}"""
        self.assertEquals(str(value), match)
 def test_save_override_file(self):
     req = self.layer['request']
     req.environ['PATH_INFO'] = '++plone++foo/bar.css'
     mng = OverrideFolderManager(self.portal)
     mng.save_file('foo/bar.css', 'foobar')
     value = self.portal.restrictedTraverse('++plone++foo/bar.css')
     self.assertEquals(str(value), 'foobar')
コード例 #3
0
    def test_override_rewrite_links(self):
        req = self.layer['request']
        req.environ['PATH_INFO'] = '++plone++foo/bar.css'
        mng = OverrideFolderManager(self.portal)
        css = """
.foo {
    background-image: url("%(site_url)s/foobar.css");
}
.bar {
    background-image: url("%(site_url)s/++plone++foo/bar/foobar.css");
}
.foobar {
    background-image: url("%(site_url)s/foo/bar/foobar.css");
}""" % {'site_url': self.portal.absolute_url()}
        mng.save_file('foo/bar.css', css)
        value = self.portal.restrictedTraverse('++plone++foo/bar.css')
        match = """
.foo {
    background-image: url("../foobar.css");
}
.bar {
    background-image: url("bar/foobar.css");
}
.foobar {
    background-image: url("../foo/bar/foobar.css");
}"""
        self.assertEquals(str(value), match)
コード例 #4
0
 def test_save_override_file(self):
     req = self.layer['request']
     req.environ['PATH_INFO'] = '++plone++foo/bar.css'
     mng = OverrideFolderManager(self.portal)
     mng.save_file('foo/bar.css', 'foobar')
     value = self.portal.restrictedTraverse('++plone++foo/bar.css')
     self.assertEquals(str(value), 'foobar')
コード例 #5
0
def update_custom_css(context, event):
    """
    This will update the custom_colors.css in plone_resources directory and will update the bundle
    registry entry when there is an event that add or modify an institution.
    """
    # First, save the compiled css in the plone_resources directory where static files are stored
    overrides = OverrideFolderManager(context)
    bundle_name = "plonemeeting.portal.core-custom"
    filepath = "static/{0}-compiled.css".format(bundle_name)
    color_custom_css_view = api.portal.get().unrestrictedTraverse(
        "@@custom_colors.css")
    compiled_css = color_custom_css_view()

    overrides.save_file(filepath, compiled_css)

    # Next, update the registry entry for the bundle
    registry = getUtility(IRegistry)
    bundles = registry.collectionOfInterface(IBundleRegistry,
                                             prefix="plone.bundles",
                                             check=False)
    bundle = bundles.get(bundle_name)
    if bundle:
        bundle.last_compilation = (datetime.now()
                                   )  # Important : it's used for cache busting
        bundle.csscompilation = "++plone++{}".format(filepath)
コード例 #6
0
 def _get_bundle_content(self) -> str:
     """Get the custom colors css directly from plone_resources"""
     overrides = OverrideFolderManager(self.institution)
     css_file_name = self._get_bundle().csscompilation.replace(
         "++plone++static/", "")
     with overrides.container["static"].openFile(css_file_name) as file:
         content = str(file.read(), "utf-8")
     return content