summaryrefslogtreecommitdiffstats
path: root/authentic/admin/settings.ptl
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2009-12-14 11:34:33 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2009-12-14 11:34:33 (GMT)
commita55f6638d1bc8dd1af1a36a788bdec7eac151420 (patch)
treebf0d9154c8ec9488d91f84eecf017b57fab0da05 /authentic/admin/settings.ptl
parent2914c9f7792f611c8d707f2aa82c9d0e822cedc1 (diff)
downloadauthentic-old-a55f6638d1bc8dd1af1a36a788bdec7eac151420.zip
authentic-old-a55f6638d1bc8dd1af1a36a788bdec7eac151420.tar.gz
authentic-old-a55f6638d1bc8dd1af1a36a788bdec7eac151420.tar.bz2
Sync themes support with wcs
Diffstat (limited to 'authentic/admin/settings.ptl')
-rw-r--r--authentic/admin/settings.ptl92
1 files changed, 63 insertions, 29 deletions
diff --git a/authentic/admin/settings.ptl b/authentic/admin/settings.ptl
index 1c29970..9c8d56e 100644
--- a/authentic/admin/settings.ptl
+++ b/authentic/admin/settings.ptl
@@ -7,6 +7,7 @@ import urllib
import urllib2
import urlparse
import tempfile
+import zipfile
import lasso
@@ -20,6 +21,7 @@ from qommon import get_cfg
from menu import *
from qommon import template
+import qommon.template
from qommon.admin.emails import EmailsDirectory
from qommon.admin.texts import TextsDirectory
@@ -673,7 +675,7 @@ class SettingsDirectory(Directory):
_q_exports = ['', 'idp', 'liberty_providers',
'identity_storage', 'identity_options', 'themes', 'passwords',
'debug_options', 'emails', 'language', 'login', 'template', 'texts',
- 'sitename', 'ssl']
+ 'sitename', 'ssl', 'upload_theme']
emails = EmailsDirectory()
texts = TextsDirectory()
@@ -880,17 +882,7 @@ class SettingsDirectory(Directory):
'<h2>%s</h2>' % _('SSL')
form.render()
-
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.encode('iso-8859-1')
-
request = get_request()
if not request.form.has_key('theme'):
@@ -898,15 +890,16 @@ class SettingsDirectory(Directory):
get_response().breadcrumb.append(('themes', _('Themes')))
html_top('settings', title = _('Themes'))
- '<h2>%s</h2>' % _('Themes')
+ "<h2>%s</h2>" % _('Themes')
+
+ get_session().display_message()
+
+ '<a rel="popup" href="upload_theme">%s</a>' % _('Upload New Theme')
+
'<form action="themes" enctype="multipart/form-data" method="post">'
- theme_files = glob.glob(os.path.join(get_publisher().DATA_DIR, str('themes/*/desc.xml')))
- theme_files.sort()
- '<ul class="biglist">'
- for t in theme_files:
- dom = xml.dom.minidom.parseString(open(t).read())
- theme = dom.getElementsByTagName('theme')[0].attributes['name'].value.encode(
- str('iso-8859-1'))
+ themes = qommon.template.get_themes()
+ '<ul class="biglist themes">'
+ for theme, (label, desc, author, icon) in sorted(themes.items()):
if current_theme == theme:
checked = ' checked="checked"'
else:
@@ -914,13 +907,12 @@ class SettingsDirectory(Directory):
'<li>'
'<strong class="label">'
' <input name="theme" value="%s" type="radio"%s>%s</input></strong>' % (
- theme, checked, getText(dom.getElementsByTagName('label')[0].childNodes))
- icon_file = t.replace(str('desc.xml'), str('icon.png'))
- if os.path.exists(icon_file):
+ theme, checked, label)
+ if icon:
'<img src="/themes/%s/icon.png" alt="" class="theme-icon" />' % theme
- '<p class="details">%s<br />by %s</p>' % (
- getText(dom.getElementsByTagName('desc')[0].childNodes),
- getText(dom.getElementsByTagName('author')[0].childNodes))
+ '<p class="details">%s' % desc
+ if author:
+ '<br/>by %s</p>' % author
'</li>'
'</ul>'
'<div class="buttons">'
@@ -928,12 +920,54 @@ class SettingsDirectory(Directory):
'</div>'
'</form>'
else:
- branding_cfg = get_cfg('branding', {})
- branding_cfg[str('theme')] = str(request.form['theme'])
- get_publisher().cfg[str('branding')] = branding_cfg
- get_publisher().write_cfg()
+ themes = qommon.template.get_themes()
+ if themes.has_key(str(request.form['theme'])):
+ branding_cfg = get_cfg('branding', {})
+ branding_cfg[str('theme')] = str(request.form['theme'])
+ get_publisher().cfg[str('branding')] = branding_cfg
+ get_publisher().write_cfg()
return redirect('.')
+ def upload_theme [html] (self):
+ form = Form(enctype='multipart/form-data')
+ form.add(FileWidget, 'file', title = _('Theme'), required = True)
+ form.add_submit('submit', _('Upload'))
+ form.add_submit('cancel', _('Cancel'))
+
+ if form.get_submit() == 'cancel':
+ return redirect('.')
+
+ if form.is_submitted() and not form.has_errors():
+ try:
+ return self.upload_theme_submit(form)
+ except ValueError:
+ form.get_widget('file').set_error(_('Invalid Theme'))
+
+ get_response().breadcrumb.append( ('upload_theme', _('Upload Theme')) )
+ html_top('forms', title = _('Upload Theme'))
+ '<h2>%s</h2>' % _('Upload Theme')
+ form.render()
+
+ def upload_theme_submit(self, form):
+ try:
+ z = zipfile.ZipFile(form.get_widget('file').parse().fp, 'r')
+ except:
+ get_session().message = ('error', _('Failed to read theme file.'))
+ return redirect('themes')
+ theme_dir = os.path.join(get_publisher().app_dir, 'themes')
+ # TODO: should check and read desc.xml first; and if theme already
+ # exists, it should remove the whole directory
+ for f in z.namelist():
+ if f[-1] == '/':
+ continue
+ path = os.path.join(theme_dir, f)
+ data = z.read(f)
+ if not os.path.exists(os.path.dirname(path)):
+ os.makedirs(os.path.dirname(path))
+ open(path, 'w').write(data)
+ z.close()
+ return redirect('themes')
+
def template [html] (self):
from qommon.template import get_default_ezt_template
branding_cfg = get_cfg('branding', {})