Last active
June 4, 2018 12:48
-
-
Save pigeonflight/48a9ae9c7d534122569cdcf4754f2eb5 to your computer and use it in GitHub Desktop.
Programmatically set the theme for your plone site using this commandline utility
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
import transaction | |
from plone import api | |
from zope.component.hooks import setSite | |
""" | |
This is a very simple approach which uses positional arguments passed to a script | |
the first argument is the id of your plone site. | |
the second argument is the name of your theme | |
usage: | |
(assuming the file is located in a folder called scripts in your buildout) | |
bin/instance run scripts/setTheme.py test my-cool-theme-2018 | |
""" | |
site_id = sys.argv[3] | |
new_theme = sys.argv[4] | |
if site_id in app.objectIds(): | |
print "The {} Plone site was found".format(site_id) | |
else: | |
print "No Plone site was found with id {}".format(site_id) | |
sys.exit(1) | |
# Sets the current site as the active site | |
setSite(app[site_id]) | |
def set_theme(): | |
portal = api.portal.get() | |
registry = api.portal.get_tool(name='portal_registry') | |
registry['plone.app.theming.interfaces.IThemeSettings.currentTheme'] = u'{}'.format(new_theme) | |
transaction.commit() | |
################################# | |
# This is where we do stuff | |
################################## | |
print("----------> -- Setting the Theme") | |
set_theme() | |
print("----------> -- Theme set to {}".format(new_theme)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment