themes support

This commit is contained in:
Frédéric Péters 2005-05-24 11:52:48 +00:00
parent 3ccb36111c
commit efdf90601a
4 changed files with 69 additions and 35 deletions

2
wcs/Defaults.py Normal file
View File

@ -0,0 +1,2 @@
APP_DIR = "/var/lib/wcs"
DATA_DIR = "/usr/share/wcs"

View File

@ -1,4 +1,9 @@
APP_DIR = '/var/tmp/wcs'
from Defaults import *
try:
from wcs_cfg import *
except ImportError:
pass
import os
import lasso
@ -15,6 +20,7 @@ __builtin__.__dict__['N_'] = lambda x: x
from quixote import enable_ptl, errors, get_session, redirect, get_session_manager
from quixote.publish import Publisher
from quixote.directory import Directory
import quixote.util
enable_ptl()
import wcs.misc
@ -49,6 +55,12 @@ class RootDirectory(Directory):
get_session_manager().expire_session()
redirect('.')
def _q_lookup(self, component):
if component != 'themes':
raise errors.TraversalError()
dirname = os.path.join(DATA_DIR, 'themes')
return quixote.util.StaticDirectory(dirname)
admin = admin.root.RootDirectory()
forms = forms.root.RootDirectory()
liberty = liberty.root.RootDirectory()

View File

@ -2,6 +2,7 @@ import cPickle
import re
import os
import lasso
import glob
from quixote import get_request, get_response, redirect
from quixote.directory import Directory
@ -165,7 +166,7 @@ class LibertyIDPUI(Directory):
class SettingsDirectory(Directory):
_q_exports = ["", "liberty_idp", "liberty_sp", ("metadata.xml", "metadata"), "theme"]
_q_exports = ["", "liberty_idp", "liberty_sp", ("metadata.xml", "metadata"), "themes"]
def _q_index [html] (self):
wcs.misc.reload_cfg()
@ -183,43 +184,15 @@ class SettingsDirectory(Directory):
"</dl>"
"<h2>%s</h2>" % _('Appearance')
"<h2>%s</h2>" % _('Branding')
"<dl>"
"""<dt><a href="theme">%s</a></dt> <dd>%s</dd>""" % (
"""<dt><a href="themes">%s</a></dt> <dd>%s</dd>""" % (
_('Theme'), _('Configure Theme'))
"</dl>"
html_foot()
def theme [html] (self):
form = Form(enctype="multipart/form-data")
form.add(StringWidget, "css", title = _('CSS Filename'),
value = wcs.misc.cfg.get('appearance', {}).get('css', None),
hint = _('Leave empty for default theme'))
form.add_submit("submit", _("Submit"))
form.add_submit("cancel", _("Cancel"))
if form.get_widget('cancel').parse():
return redirect('.')
if not form.is_submitted() or form.has_errors():
html_top('settings', title = _('Theme'))
'<h2>%s</h2>' % _('Theme')
form.render()
html_foot()
else:
wcs.misc.reload_cfg()
if not wcs.misc.cfg.has_key(str('appearance')):
wcs.misc.cfg[str('appearance')] = {}
css = form.get_widget('css').parse()
if not css:
del wcs.misc.cfg[str('appearance')][str('css')]
else:
wcs.misc.cfg[str('appearance')][str('css')] = str(css)
wcs.misc.write_cfg()
return redirect('.')
def liberty_sp [html] (self):
wcs.misc.reload_cfg()
base_url = wcs.misc.cfg.get("sp", {}).get('base_url', None)
@ -339,3 +312,49 @@ class SettingsDirectory(Directory):
self.get_metadata()
liberty_idp = LibertyIDPDir()
def themes [html] (self):
import xml.dom.minidom
def getText(nodelist):
rc = ""
for node in nodelist:
if node.nodeType == node.TEXT_NODE:
rc = rc + node.data
return rc
request = get_request()
if not request.form.has_key('theme'):
current_theme = wcs.misc.cfg.get('branding', {}).get('theme', 'default')
html_top('settings', title = _('Themes'))
"<h2>%s</h2>" % _('Themes')
'<form action="themes" enctype="multipart/form-data" method="post">'
theme_files = glob.glob(os.path.join(wcs.DATA_DIR, str('themes/*/desc.xml')))
theme_files.sort()
for t in theme_files:
dom = xml.dom.minidom.parseString(open(t).read())
theme = dom.getElementsByTagName('theme')[0].attributes['name'].value
if current_theme == theme:
checked = ' checked="checked"'
else:
checked = ''
'<div class="theme">'
'<h3><input name="theme" value="%s" type="radio"%s>%s</input></h3>' % (
theme, checked, getText(dom.getElementsByTagName('label')[0].childNodes))
"<p>%s</p>" % getText(dom.getElementsByTagName('desc')[0].childNodes)
"<p>by %s</p>" % getText(dom.getElementsByTagName('author')[0].childNodes)
'</div>'
'<div class="buttons">'
'<input type="submit" name="submit" value="%s" />' % _('Submit')
'</div>'
'</form>'
html_foot()
else:
if not wcs.misc.cfg.has_key('branding'):
wcs.misc.cfg[str('branding')] = {}
wcs.misc.cfg[str('branding')][str('theme')] = str(request.form['theme'])
wcs.misc.write_cfg()
return redirect('.')

View File

@ -13,10 +13,11 @@ from wcs import storage
def html_top [html] (title = None):
try:
css = wcs.misc.cfg['appearance']['css']
except KeyError:
current_theme = wcs.misc.cfg.get('branding', {}).get('theme', 'default')
if current_theme == 'default':
css = '/css/wcs.css'
else:
css = '/themes/%s/wcs.css' % current_theme
return """<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>%s</title>