示例#1
0
def getAvailableRapidoApps(exclude_theme=None):
    themes = getAvailableThemes()
    apps = dict()
    for theme in themes:
        if theme.__name__ not in ["template", "barceloneta"] and theme.__name__ != exclude_theme:
            apps[theme.__name__] = getRapidoAppFromTheme(theme.__name__)
    return apps
示例#2
0
    def test_getAvailableThemes(self):
        from plone.app.theming.utils import getAvailableThemes
        from plone.app.theming.utils import getTheme

        themes = getAvailableThemes()

        self.assertTrue(len(themes) >= 3)
        theme = getTheme('plone.app.theming.tests')
        self.assertTrue(theme is not None)
        self.assertEqual(theme.__name__, 'plone.app.theming.tests')
        self.assertEqual(theme.title, 'Test theme')
        self.assertEqual(theme.description, 'A theme for testing')
        self.assertEqual(
            theme.rules,
            '/++theme++plone.app.theming.tests/rules.xml'
        )
        self.assertEqual(
            theme.absolutePrefix,
            '/++theme++plone.app.theming.tests'
        )
        self.assertEqual(
            theme.parameterExpressions,
            {'foo': "python:request.get('bar')"}
        )
        self.assertEqual(theme.doctype, "<!DOCTYPE html>")
    def __call__(self):
        """
        """
        local_registry = self.context.get('local_registry')
        #If registry is not present, then create it
        if local_registry is None:
            enableChildRegistry(self.context, None)

        registry = queryUtility(IRegistry)
        if registry != self.context.get('local_registry'):
            return

        settings = registry.forInterface(IThemeSettings, False)
        themes = getAvailableThemes()

        if self.context.theme:
            settings.enabled = self.context.theme != DISABLE_PLONE_APP_THEMING
            for theme in themes:
                if theme.rules == self.context.theme:
                    settings.currentTheme = theme.__name__.decode()
                    settings.rules = theme.rules
                    settings.absolutePrefix = theme.absolutePrefix
                    settings.parameterExpressions = theme.parameterExpressions
                    settings.doctype = theme.doctype
        else:
            return
            fields = getFields(IThemeSettings)
            settings_fields = ('currentTheme', 'rules', 'absolutePrefix', 'parameterExpressions', 'doctype',)
            for settings_field in settings_fields:
                setattr(settings, settings_field, fields[settings_field].default)
示例#4
0
    def test_theme_enabled_resource_directory(self):

        app = self.layer['app']
        portal = self.layer['portal']

        self.settings.enabled = True
        theme = getAvailableThemes()[0]
        applyTheme(theme)
        self.assertEqual(self.settings.rules, u'/++theme++plone.app.theming.tests/rules.xml')
        self.assertEqual(self.settings.currentTheme, u"plone.app.theming.tests")
        self.assertEqual(self.settings.doctype, u"<!DOCTYPE html>")
        import transaction; transaction.commit()

        browser = Browser(app)
        browser.open(portal.absolute_url())

        # Title - pulled in with rules.xml
        self.assertTrue(portal.title in browser.contents)

        # Elsewhere - not pulled in
        self.assertFalse("Accessibility" in browser.contents)

        # The theme
        self.assertTrue("This is the theme" in browser.contents)

        # Doctype
        self.assertTrue(re.match("<!DOCTYPE html>\s+<html",browser.contents))
示例#5
0
 def testBrowserLayerRegistered(self):
     sm = getSiteManager(self.portal)
     themes = getAvailableThemes()
     assert len(themes) > 0, "No theme installed"
     theme = themes[0]
     assert theme.__name__ == 'paragon.theme'
     assert theme.absolutePrefix == '/++theme++paragon.theme'
示例#6
0
    def test_applyTheme(self):
        from zope.component import getUtility

        from plone.registry.interfaces import IRegistry

        from plone.app.theming.interfaces import IThemeSettings
        from plone.app.theming.utils import getAvailableThemes
        from plone.app.theming.utils import applyTheme

        theme = None
        for t in getAvailableThemes():
            theme = t
            break

        settings = getUtility(IRegistry).forInterface(IThemeSettings, False)
        settings.rules = None

        applyTheme(theme)

        self.assertEqual(settings.rules, theme.rules)
        self.assertEqual(settings.absolutePrefix, theme.absolutePrefix)
        self.assertEqual(
            settings.parameterExpressions,
            theme.parameterExpressions
        )
        self.assertEqual(settings.doctype, theme.doctype)
示例#7
0
    def _setup(self):
        self.settings = getUtility(IRegistry).forInterface(IThemeSettings, False)
        self.zodbThemes = getZODBThemes()
        self.availableThemes = getAvailableThemes()
        self.selectedTheme = self.getSelectedTheme(self.availableThemes, self.settings.rules)

        # Set response header to make sure control panel is never themed
        self.request.response.setHeader('X-Theme-Disabled', '1')
 def update(self):
     if self.portal_registry is None:
         self.portal_registry = component.queryUtility(IRegistry)
     if self.available_themes is None:
         self.available_themes = [t.__name__ for t in getAvailableThemes()]
     if self.available_skins is None:
         portal_skins = getToolByName(self.context, 'portal_skins')
         self.available_skins = portal_skins.getSkinSelections()
def getDiazoThemes(context):
    """Get a list of all Diazo themes.
    """
    themes = getAvailableThemes()
    terms = [SimpleTerm(theme.rules, theme.rules, theme.title)
             for theme in themes
             if theme.__name__ != TEMPLATE_THEME]
    terms.insert(0, (SimpleTerm('', '', _(u'No local theme'))))

    return SimpleVocabulary(terms)
def ThemeVocabulary(context):
    """ Get a list of all ITheme's available in resource directories and make
    a vocabulary.    """

    themes = getAvailableThemes()

    terms = [SimpleTerm(value=theme.__name__,
            token=theme.__name__,
            title=theme.title) for theme in themes]

    return SimpleVocabulary(terms)
示例#11
0
    def _setup(self):
        self.settings = getUtility(IRegistry).forInterface(IThemeSettings, False)
        self.zodbThemes = getZODBThemes()
        self.availableThemes = getAvailableThemes()
        self.selectedTheme = self.getSelectedTheme(self.availableThemes, self.settings.rules)
        self.overlay = ''

        self.skinsSettings = ISkinsSchema(self.context)
        self.skinsVocabulary = getUtility(IVocabularyFactory, name='plone.app.vocabularies.Skins')(self.context)

        # Set response header to make sure control panel is never themed
        self.request.response.setHeader('X-Theme-Disabled', '1')
示例#12
0
    def transformIterable(self, result, encoding):
        """Apply the transform if required
        """
        #import pdb; pdb.set_trace()
        active = False
        registry = getUtility(IRegistry)

        base1 = self.request.get('BASE1')
        _xx_, base1 = base1.split('://', 1)
        host = base1.lower()
        serverPort = self.request.get('SERVER_PORT')

        hostnames = registry[
            'zettwerk.mobile.interfaces.IMobileSettings.hostnames'
        ]
        themename = registry[
            'zettwerk.mobile.interfaces.IMobileSettings.themename'
        ]
        if hostnames:
            for hostname in hostnames or ():
                if host == hostname or \
                   hostname == "http://%s" % (host):
                    active = True

        availableThemes = getAvailableThemes()
        mobile = None
        for item in availableThemes:
            if item.__name__ == themename:
                mobile = item
                active = active and True

        if not active:
            ## return the default theme
            result = super(MobileThemeTransform, self) \
                .transformIterable(result, encoding)
            return result

        registry = queryUtility(IRegistry)
        settings = registry.forInterface(IThemeSettings, False)

        class S(object):
            rules = mobile.rules

            doctype = settings.doctype
            absolutePrefix = settings.absolutePrefix
            readNetwork = settings.readNetwork
            parameterExpressions = settings.parameterExpressions

        fake_settings = S()

        return self.transformIterableWithSettings(result, encoding,
                                                  fake_settings)
示例#13
0
    def _setup(self):
        registry = getUtility(IRegistry)
        self.theme_settings = registry.forInterface(IThemeSettings, False)
        self.link_settings = registry.forInterface(ILinkSchema, prefix="plone", check=False)
        self.zodbThemes = getZODBThemes()
        self.availableThemes = getAvailableThemes()
        self.selectedTheme = self.getSelectedTheme(self.availableThemes, self.theme_settings.rules)
        self.overlay = ""

        self.skinsVocabulary = getUtility(IVocabularyFactory, name="plone.app.vocabularies.Skins")(self.context)

        # Set response header to make sure control panel is never themed
        self.request.response.setHeader("X-Theme-Disabled", "1")
示例#14
0
def importTheme(context):
    """Apply the theme with the id contained in the profile file theme.xml
    and enable the theme.
    """

    data = context.readDataFile('theme.xml')
    if not data:
        return

    logger = context.getLogger('plone.app.theming.exportimport')

    tree = etree.fromstring(data)

    # apply theme if given and valid
    themeName = tree.find("name")
    if themeName is not None:
        themeName = themeName.text.strip()
        themeInfo = None

        allThemes = getAvailableThemes()
        for info in allThemes:
            if info.__name__.lower() == themeName.lower():
                themeInfo = info
                break

        if themeInfo is None:
            raise ValueError("Theme {0:s} is not available".format(themeName))

        applyTheme(themeInfo)
        logger.info('Theme {0:s} applied'.format(themeName))

    # enable/disable theme
    themeEnabled = tree.find("enabled")
    if themeEnabled is None:
        return

    settings = getUtility(IRegistry).forInterface(IThemeSettings, False)

    themeEnabled = themeEnabled.text.strip().lower()
    if themeEnabled in ("y", "yes", "true", "t", "1", "on",):
        settings.enabled = True
        logger.info('Theme enabled')
    elif themeEnabled in ("n", "no", "false", "f", "0", "off",):
        settings.enabled = False
        logger.info('Theme disabled')
    else:
        raise ValueError(
            "{0:s} is not a valid value for <enabled />".format(themeEnabled)
        )
示例#15
0
    def _setup(self):
        self.settings = getUtility(IRegistry).forInterface(
            IThemeSettings, False)
        self.zodbThemes = getZODBThemes()
        self.availableThemes = getAvailableThemes()
        self.selectedTheme = self.getSelectedTheme(self.availableThemes,
                                                   self.settings.rules)
        self.overlay = ''

        self.skinsVocabulary = getUtility(IVocabularyFactory,
                                          name='plone.app.vocabularies.Skins')(
                                              self.context)

        # Set response header to make sure control panel is never themed
        self.request.response.setHeader('X-Theme-Disabled', '1')
示例#16
0
    def getCurrentTheme(self):
        """The name of the current theme."""
        settings = self.getSettings()
        if not settings.rules:
            return None
        if settings.currentTheme:
            return settings.currentTheme

        # BBB: If currentTheme isn't set, look for a theme with a rules file
        # matching that of the current theme
        for theme in utils.getAvailableThemes():
            if theme.rules == settings.rules:
                return theme.__name__

        return None
示例#17
0
    def getCurrentTheme(self):
        """The name of the current theme."""
        settings = self.getSettings()
        if not settings.rules:
            return None
        if settings.currentTheme:
            return settings.currentTheme

        # BBB: If currentTheme isn't set, look for a theme with a rules file
        # matching that of the current theme
        for theme in utils.getAvailableThemes():
            if theme.rules == settings.rules:
                return theme.__name__

        return None
示例#18
0
    def test_getAvailableThemes(self):
        from plone.app.theming.utils import getAvailableThemes
        from plone.app.theming.utils import getTheme

        themes = getAvailableThemes()

        self.assertEqual(len(themes), 3)
        theme = getTheme('plone.app.theming.tests')
        self.assertTrue(theme is not None)
        self.assertEqual(theme.__name__, 'plone.app.theming.tests')
        self.assertEqual(theme.title, 'Test theme')
        self.assertEqual(theme.description, 'A theme for testing')
        self.assertEqual(theme.rules, '/++theme++plone.app.theming.tests/rules.xml')
        self.assertEqual(theme.absolutePrefix, '/++theme++plone.app.theming.tests')
        self.assertEqual(theme.parameterExpressions, {'foo': "python:request.get('bar')"})
        self.assertEqual(theme.doctype, "<!DOCTYPE html>")
示例#19
0
def importTheme(context):
    """Apply the theme with the id contained in the profile file theme.xml
    and enable the theme.
    """

    data = context.readDataFile('theme.xml')
    if not data:
        return

    logger = context.getLogger('plone.app.theming.exportimport')

    tree = etree.fromstring(data)

    themeName = tree.find("name")
    themeEnabled = tree.find("enabled")

    if themeName is not None:
        themeName = themeName.text.strip()
        themeInfo = None

        allThemes = getAvailableThemes()
        for info in allThemes:
            if info.__name__.lower() == themeName.lower():
                themeInfo = info
                break

        if themeInfo is None:
            raise ValueError("Theme %s is not available" % themeName)

        applyTheme(themeInfo)
        logger.info('Theme %s applied' % themeName)

    toadapt = (getSite(), getRequest())
    settings = getMultiAdapter(toadapt, IThemeSettings)

    if themeEnabled is not None:
        themeEnabled = themeEnabled.text.strip().lower()

        if themeEnabled in ("y", "yes", "true", "t", "1", "on",):
            settings.enabled = True
            logger.info('Theme enabled')
        elif themeEnabled in ("n", "no", "false", "f", "0", "off",):
            settings.enabled = False
            logger.info('Theme disabled')
        else:
            raise ValueError("%s is not a valid value for <enabled />" % themeEnabled)
示例#20
0
    def test_createThemeFromTemplate_custom_prefix(self):
        from plone.app.theming.utils import createThemeFromTemplate
        from plone.app.theming.utils import getAvailableThemes
        from plone.app.theming.utils import getTheme
        from plone.app.theming.interfaces import THEME_RESOURCE_NAME
        from plone.app.theming.interfaces import RULE_FILENAME
        title = "copy of test theme with custom prefix"
        description = "test theme creation"
        themeName = createThemeFromTemplate(title, description,
                                            baseOn="secondary-theme")
        titles = [theme.title for theme in getAvailableThemes()]
        self.assertTrue(title in titles)

        theme = getTheme(themeName)
        expected_prefix = u"/++%s++%s" % (THEME_RESOURCE_NAME,
                                          title.replace(" ", "-"))
        self.assertEqual(theme.absolutePrefix, expected_prefix)

        expected_rules = u"/++%s++%s/%s" % (THEME_RESOURCE_NAME,
                                            title.replace(" ", "-"),
                                            RULE_FILENAME)
        self.assertEqual(theme.rules, expected_rules)

        self.assertEqual(theme.enabled_bundles, ['plone'])
        self.assertEqual(theme.disabled_bundles, ['foobar'])

        expected_dev_css = u"/++%s++%s/less/barceloneta.plone.less" % (
            THEME_RESOURCE_NAME, title.replace(" ", "-"))
        expected_prod_css = u"/++%s++%s/less/barceloneta-compiled.css" % (
            THEME_RESOURCE_NAME, title.replace(" ", "-"))
        expected_tinymce = u"/++%s++%s/less/barceloneta-compiled.css" % (
            THEME_RESOURCE_NAME, title.replace(" ", "-"))
        self.assertEqual(theme.development_css, expected_dev_css)
        self.assertEqual(theme.production_css, expected_prod_css)
        self.assertEqual(theme.tinymce_content_css, expected_tinymce)

        expected_dev_js = u"/++%s++%s/script.js" % (
            THEME_RESOURCE_NAME, title.replace(" ", "-"))
        expected_prod_js = u"/++%s++%s/script.min.js" % (
            THEME_RESOURCE_NAME, title.replace(" ", "-"))
        self.assertEqual(theme.development_js, expected_dev_js)
        self.assertEqual(theme.production_js, expected_prod_js)
示例#21
0
    def test_createThemeFromTemplate_rel_path(self):
        from plone.app.theming.utils import createThemeFromTemplate
        from plone.app.theming.utils import getAvailableThemes
        from plone.app.theming.utils import getTheme
        from plone.app.theming.interfaces import THEME_RESOURCE_NAME
        from plone.app.theming.interfaces import RULE_FILENAME
        title = "copy of test theme with custom prefix"
        description = "test theme creation"
        themeName = createThemeFromTemplate(title,
                                            description,
                                            baseOn="another-theme")
        titles = [theme.title for theme in getAvailableThemes()]
        self.assertTrue(title in titles)

        theme = getTheme(themeName)
        expected_prefix = u"/++%s++%s" % (THEME_RESOURCE_NAME,
                                          title.replace(" ", "-"))
        self.assertEqual(theme.absolutePrefix, expected_prefix)

        expected_rules = u"/++%s++%s/%s" % (
            THEME_RESOURCE_NAME, title.replace(" ", "-"), RULE_FILENAME)
        self.assertEqual(theme.rules, expected_rules)

        self.assertEqual(theme.enabled_bundles, ['plone'])
        self.assertEqual(theme.disabled_bundles, ['foobar'])

        expected_dev_css = u"++%s++%s/less/barceloneta.plone.less" % (
            THEME_RESOURCE_NAME, title.replace(" ", "-"))
        expected_prod_css = u"++%s++%s/less/barceloneta-compiled.css" % (
            THEME_RESOURCE_NAME, title.replace(" ", "-"))
        expected_tinymce = u"++%s++%s/less/barceloneta-compiled.css" % (
            THEME_RESOURCE_NAME, title.replace(" ", "-"))
        self.assertEqual(theme.development_css, expected_dev_css)
        self.assertEqual(theme.production_css, expected_prod_css)
        self.assertEqual(theme.tinymce_content_css, expected_tinymce)

        expected_dev_js = u"++%s++%s/script.js" % (THEME_RESOURCE_NAME,
                                                   title.replace(" ", "-"))
        expected_prod_js = u"++%s++%s/script.min.js" % (
            THEME_RESOURCE_NAME, title.replace(" ", "-"))
        self.assertEqual(theme.development_js, expected_dev_js)
        self.assertEqual(theme.production_js, expected_prod_js)
示例#22
0
    def test_applyTheme(self):
        from zope.globalrequest import getRequest
        from plone.app.theming.interfaces import IThemeSettings
        from plone.app.theming.utils import getAvailableThemes
        from plone.app.theming.utils import applyTheme

        toadapt = (self.layer['portal'], getRequest())
        settings = getMultiAdapter(toadapt, IThemeSettings)

        theme = None
        for t in getAvailableThemes():
            theme = t
            break

        self.assertEqual(settings.rules, None)
        applyTheme(theme)

        self.assertEqual(settings.rules, theme.rules)
        self.assertEqual(settings.absolutePrefix, theme.absolutePrefix)
        self.assertEqual(settings.parameterExpressions, theme.parameterExpressions)
        self.assertEqual(settings.doctype, theme.doctype)
    def transformIterable(self, result, encoding):
        """Apply the transform if required
        """
        active = self._getActive()

        registry = getUtility(IRegistry)
        themename = registry[
            'zettwerk.mobiletheming.interfaces.IMobileThemingSettings' \
                '.themename'
        ]

        availableThemes = getAvailableThemes()
        mobile = None
        for item in availableThemes:
            if item.__name__ == themename:
                mobile = item
                active = active and True

        if not active or mobile is None:
            ## return the default theme
            result = super(MobileThemeTransform, self) \
                .transformIterable(result, encoding)
            return result

        registry = queryUtility(IRegistry)
        settings = registry.forInterface(IThemeSettings, False)

        class S(object):
            rules = mobile.rules

            doctype = settings.doctype
            absolutePrefix = settings.absolutePrefix
            readNetwork = settings.readNetwork
            parameterExpressions = settings.parameterExpressions

        fake_settings = S()

        return self.transformIterableWithSettings(result, encoding,
                                                  fake_settings)
示例#24
0
    def test_createThemeFromTemplate(self):
        from plone.app.theming.utils import createThemeFromTemplate
        from plone.app.theming.utils import getAvailableThemes
        from plone.app.theming.utils import getTheme
        from plone.app.theming.interfaces import THEME_RESOURCE_NAME
        from plone.app.theming.interfaces import RULE_FILENAME
        title = "copy of test theme"
        description = "test theme creation"
        themeName = createThemeFromTemplate(title, description,
                                            baseOn="plone.app.theming.tests")
        titles = [theme.title for theme in getAvailableThemes()]
        self.assertTrue(title in titles)

        theme = getTheme(themeName)
        expected_prefix = u"/++%s++%s" % (THEME_RESOURCE_NAME,
                                          title.replace(" ", "-"))
        self.assertEqual(theme.absolutePrefix, expected_prefix)

        expected_rules = u"/++%s++%s/%s" % (THEME_RESOURCE_NAME,
                                            title.replace(" ", "-"),
                                            RULE_FILENAME)
        self.assertEqual(theme.rules, expected_rules)
示例#25
0
    def test_createThemeFromTemplate(self):
        from plone.app.theming.utils import createThemeFromTemplate
        from plone.app.theming.utils import getAvailableThemes
        from plone.app.theming.utils import getTheme
        from plone.app.theming.interfaces import THEME_RESOURCE_NAME
        from plone.app.theming.interfaces import RULE_FILENAME
        title = "copy of test theme"
        description = "test theme creation"
        themeName = createThemeFromTemplate(title,
                                            description,
                                            baseOn="plone.app.theming.tests")
        titles = [theme.title for theme in getAvailableThemes()]
        self.assertTrue(title in titles)

        theme = getTheme(themeName)
        expected_prefix = u"/++%s++%s" % (THEME_RESOURCE_NAME,
                                          title.replace(" ", "-"))
        self.assertEqual(theme.absolutePrefix, expected_prefix)

        expected_rules = u"/++%s++%s/%s" % (
            THEME_RESOURCE_NAME, title.replace(" ", "-"), RULE_FILENAME)
        self.assertEqual(theme.rules, expected_rules)
示例#26
0
    def __call__(self):
        """
        """
        registry = queryUtility(IRegistry)
        if registry != self.context['local_registry']:
            return
        settings = registry.forInterface(IThemeSettings, False)
        themes = getAvailableThemes()

        if self.context.theme:
            for theme in themes:
                if theme.rules == self.context.theme:
                    settings.currentTheme = theme.__name__.decode()
                    settings.rules = theme.rules
                    settings.absolutePrefix = theme.absolutePrefix
                    settings.parameterExpressions = theme.parameterExpressions
                    settings.doctype = theme.doctype
        else:
            fields = getFields(IThemeSettings)
            settings_fields = ('currentTheme', 'rules', 'absolutePrefix', 'parameterExpressions', 'doctype',)
            for settings_field in settings_fields:
                setattr(settings, settings_field, fields[settings_field].default)
示例#27
0
    def test_applyTheme(self):
        from zope.component import getUtility

        from plone.registry.interfaces import IRegistry

        from plone.app.theming.interfaces import IThemeSettings
        from plone.app.theming.utils import getAvailableThemes
        from plone.app.theming.utils import applyTheme

        settings = getUtility(IRegistry).forInterface(IThemeSettings, False)

        theme = None
        for t in getAvailableThemes():
            theme = t
            break

        self.assertEqual(settings.rules, None)
        applyTheme(theme)

        self.assertEqual(settings.rules, theme.rules)
        self.assertEqual(settings.absolutePrefix, theme.absolutePrefix)
        self.assertEqual(settings.parameterExpressions, theme.parameterExpressions)
        self.assertEqual(settings.doctype, theme.doctype)
 def test_temas_disponiveis(self):
     themes = getAvailableThemes()
     # Nosso tema + os dois do Plone
     self.assertEqual(len(themes), 3)
示例#29
0
 def test_available_themes(self):
     from plone.app.theming.utils import getAvailableThemes
     themes = getAvailableThemes()
     self.assertEqual(len(themes), 5)
示例#30
0
def getTheme(name):
    themes = getAvailableThemes()
    for theme in themes:
        if theme.__name__ == name:
            return theme
示例#31
0
 def test_temas_disponiveis(self):
     themes = getAvailableThemes()
     # Nosso tema + os dois do Plone
     self.assertEqual(len(themes), 3)