admin: adapt theme handling (#36515)

This commit is contained in:
Frédéric Péters 2019-11-13 17:52:40 +01:00
parent 9cb2e4cc43
commit f8587a00e1
2 changed files with 17 additions and 21 deletions

View File

@ -4546,7 +4546,7 @@ def test_settings_idp(pub):
resp2 = resp2.form.submit('submit')
resp_metadata = app.get('/saml/metadata', status=200)
assert resp_metadata.body.startswith('<?xml')
assert resp_metadata.text.startswith('<?xml')
resp2 = resp.click('Identity Providers')
resp2 = resp2.click('New')
idp_metadata_filename = os.path.join(os.path.dirname(__file__), 'idp_metadata.xml')
@ -4556,7 +4556,7 @@ def test_settings_idp(pub):
resp = resp.click('Identity Providers')
assert 'http://authentic.example.net/' in resp.text
resp2 = resp.click(href='http-authentic.example.net-idp-saml2-metadata/', index=0)
assert 'ns0:EntityDescriptor' in resp2.body
assert 'ns0:EntityDescriptor' in resp2.text
resp = resp.click(href='http-authentic.example.net-idp-saml2-metadata/edit')
resp = resp.forms[0].submit('submit')
resp = resp.follow()
@ -5212,7 +5212,7 @@ def test_settings_theme_preview(pub):
formdef.store()
app = login(get_app(pub))
assert not 'alto/wcs.css' in app.get('/').body
assert not 'alto/wcs.css' in app.get('/').text
resp = app.get('/backoffice/settings/themes')
assert resp.form['theme'].value in ('default', 'django')
@ -5255,8 +5255,8 @@ def test_settings_theme_download_upload(pub):
resp = resp.form.submit()
assert os.path.exists(os.path.join(pub.app_dir, 'themes/alto/foobar.txt'))
assert app.get('/themes/alto/foobar.txt').body == 'XXX'
assert 'Directory listing denied' in app.get('/themes/alto/', status=200).body
assert app.get('/themes/alto/foobar.txt').text == 'XXX'
assert 'Directory listing denied' in app.get('/themes/alto/', status=200).text
assert app.get('/themes/alto/plop', status=404)
assert app.get('/themes/alto/../', status=404)

View File

@ -38,7 +38,7 @@ from . import ezt, force_str
def get_template_from_script(filename):
local_result = {}
execfile(filename, {
exec(open(filename).read(), {
'publisher': get_publisher(),
'request': get_request(),
'__file__': filename}, local_result)
@ -98,17 +98,13 @@ def get_theme_dict(theme_xml):
except: # parse error
return None
publisher = get_publisher()
def encode_string(x):
if publisher:
return force_text(x).encode(publisher.site_charset)
return x
name = encode_string(tree.attrib['name'])
version = tree.attrib.get('version')
label = encode_string(tree.findtext('label'))
desc = encode_string(tree.findtext('desc'))
author = encode_string(tree.findtext('author'))
name = force_str(tree.attrib['name'])
version = force_str(tree.attrib.get('version') or '')
label = force_str(tree.findtext('label') or '')
desc = force_str(tree.findtext('desc') or '')
author = force_str(tree.findtext('author') or '')
icon = None
if type(theme_xml) is str:
if isinstance(theme_xml, six.string_types):
icon = os.path.join(os.path.dirname(theme_xml), 'icon.png')
if not os.path.exists(icon):
icon = None
@ -226,20 +222,20 @@ def get_default_ezt_template():
filename = os.path.join(get_publisher().app_dir, 'themes',
current_theme, 'template.%s.ezt' % get_publisher().APP_NAME)
if os.path.exists(filename):
return file(filename).read()
return open(filename).read()
filename = os.path.join(get_publisher().data_dir, 'themes',
current_theme, 'template.%s.ezt' % get_publisher().APP_NAME)
if os.path.exists(filename):
return file(filename).read()
return open(filename).read()
filename = os.path.join(get_publisher().app_dir, 'themes', current_theme, 'template.ezt')
if os.path.exists(filename):
return file(filename).read()
return open(filename).read()
filename = os.path.join(get_publisher().data_dir, 'themes', current_theme, 'template.ezt')
if os.path.exists(filename):
return file(filename).read()
return open(filename).read()
return DEFAULT_TEMPLATE_EZT
@ -385,7 +381,7 @@ def decorate(body, response):
for dname in possible_dirnames:
filename = os.path.join(dname, fname)
if os.path.exists(filename):
template_ezt = file(filename).read()
template_ezt = open(filename).read()
break
else:
continue