handle can_logo and can_theme permissions

This commit is contained in:
Frédéric Péters 2011-04-21 12:12:18 +02:00
parent 9734a7a83f
commit 913182d31d
4 changed files with 43 additions and 8 deletions

View File

@ -65,6 +65,10 @@ body div#popup h2 {
padding-top: 3px;
}
div.themes hr {
visibility: hidden;
}
div.themes div.theme {
border: 1px dotted #888;
margin: 1em;
@ -122,10 +126,8 @@ div#main-content {
div#logo-selection {
clear: both;
padding-top: 1em;
}
div#logo-selection form {
margin: 1em;
}

View File

@ -171,7 +171,8 @@ class RootDirectory(AccessControlled, Directory):
'<ul>'
' <li><a href="config/sitetitle" rel="popup">%s</a></li>' % _('Title')
' <li><a href="config/homepage">%s</a></li>' % _('Home Page Text')
' <li><a href="config/appearance">%s</a></li>' % _('Appearance')
if quota.can_logo() or quota.can_theme():
' <li><a href="config/appearance">%s</a></li>' % _('Appearance')
' <li><a href="config/texts/">%s</a></li>' % _('Message Texts')
'</ul>'
'</div>'

View File

@ -30,6 +30,9 @@ import qommon.admin.texts
from qommon.form import *
import quota
def get_logo_url():
pages_data_dir = os.path.join(get_publisher().app_dir, 'pages', 'data')
for f in ('png', 'jpeg', 'gif'):
@ -179,8 +182,18 @@ class ConfigDirectory(Directory):
redirect('.')
def appearance [html] (self):
request = get_request()
get_response().breadcrumb.append(('appearance', _('Appearance')))
html_top('config', title = _('Appearance'))
if quota.can_theme():
"<h2>%s</h2>" % _('Appearance')
self.appearance_theme()
if quota.can_logo():
self.appearance_logo()
def appearance_theme [html] (self):
request = get_request()
if request.form.has_key('theme'):
themes = qommon.template.get_themes()
if themes.has_key(str(request.form['theme'])):
@ -191,10 +204,6 @@ class ConfigDirectory(Directory):
current_theme = get_cfg('branding', {}).get('theme', 'default')
get_response().breadcrumb.append(('appearance', _('Appearance')))
html_top('config', title = _('Appearance'))
"<h2>%s</h2>" % _('Appearance')
'<div class="themes">'
'<p>'
@ -215,8 +224,10 @@ class ConfigDirectory(Directory):
'<img src="/themes/%s/icon.png" alt="" class="theme-icon" />' % theme
'</a>'
'</div>'
'<hr class="clear" />'
'</div>'
def appearance_logo [html] (self):
'<div id="logo-selection">'
'<h2>%s</h2>' % _('Logo')
@ -236,7 +247,11 @@ class ConfigDirectory(Directory):
'</form>'
'</div>'
def logo(self):
if not quota.can_logo():
raise errors.NotAvailableFeature()
form = Form(enctype='multipart/form-data', use_tokens=False)
form.add(FileWidget, 'file', title = _('Theme'), required=True)
form.add_submit('submit', _('Upload'))

View File

@ -29,6 +29,12 @@ class QuotaExceeded(AccessError):
return template.error_page(_('Quota Exceeded'),
continue_to = (get_publisher().get_root_url(), _('the homepage')))
class NotAvailableFeature(AccessError):
def render(self):
return template.error_page(_('This feature is not available.'),
continue_to = (get_publisher().get_root_url(), _('the homepage')))
def get_max_number_of_forms():
t = get_request().get_header('x-asec-quota-forms')
if not t:
@ -72,3 +78,14 @@ def may_add_a_new_answer(formdef):
answers_count = formdef.data_class().count()
return (answers_count < max_answers)
def get_boolean_quota(s):
v = get_request().get_header(s)
if v and v.lower() == 'true':
return True
return False
def can_logo():
return get_boolean_quota('x-asec-can-logo')
def can_theme():
return get_boolean_quota('x-asec-can-theme')