From 5004e91c9906c60764c67713a122836aeac47e41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Wed, 29 Jun 2016 08:48:01 +0200 Subject: [PATCH] general: serve all static files from /static/ (#11582) --- tests/test_ctl.py | 3 ++ tests/test_rootdirectory.py | 10 ++--- wcs/ctl/collectstatic.py | 3 +- wcs/qommon/http_response.py | 17 +++----- wcs/qommon/publisher.py | 2 +- wcs/root.py | 97 ++++++++++++++++++++++----------------------- 6 files changed, 64 insertions(+), 68 deletions(-) diff --git a/tests/test_ctl.py b/tests/test_ctl.py index 7c21ba3..2f420e8 100644 --- a/tests/test_ctl.py +++ b/tests/test_ctl.py @@ -21,5 +21,8 @@ def test_loading(): def test_collectstatic(pub): CmdCollectStatic.collectstatic(pub) assert os.path.exists(os.path.join(pub.app_dir, 'collectstatic', 'css', 'wcs.css')) + assert os.path.exists(os.path.join(pub.app_dir, 'collectstatic', 'css', 'qommon.css')) + assert os.path.exists(os.path.join(pub.app_dir, 'collectstatic', 'css', 'gadjo.css')) + assert os.path.exists(os.path.join(pub.app_dir, 'collectstatic', 'xstatic', 'jquery.js')) CmdCollectStatic.collectstatic(pub, clear=True, link=True) assert os.path.islink(os.path.join(pub.app_dir, 'collectstatic', 'css', 'wcs.css')) diff --git a/tests/test_rootdirectory.py b/tests/test_rootdirectory.py index 7e48235..cef5b4d 100644 --- a/tests/test_rootdirectory.py +++ b/tests/test_rootdirectory.py @@ -150,14 +150,14 @@ def test_advertized_site_user_access(): assert 'authentication required' in output # locales ? def test_static_directories(): - assert get_app(pub).get('/css/wcs.css') - assert get_app(pub).get('/images/feed-icon-10x10.png') - assert get_app(pub).get('/qo/css/qommon.css') + assert get_app(pub).get('/static/css/wcs.css') + assert get_app(pub).get('/static/images/feed-icon-10x10.png') + assert get_app(pub).get('/static/css/qommon.css') if os.path.exists('/usr/share/javascript/leaflet/'): - assert get_app(pub).get('/leaflet/leaflet.js') + assert get_app(pub).get('/static/leaflet/leaflet.js') assert get_app(pub).get('/static/css/gadjo.css') assert get_app(pub).get('/static/xstatic/jquery.js') assert get_app(pub).get('/static/xstatic/jquery-ui.js') - assert 'Directory listing denied' in get_app(pub).get('/css/').body + assert 'Directory listing denied' in get_app(pub).get('/static/css/').body assert get_app(pub).get('/static/xxx', status=404) diff --git a/wcs/ctl/collectstatic.py b/wcs/ctl/collectstatic.py index 8ca758c..596777c 100644 --- a/wcs/ctl/collectstatic.py +++ b/wcs/ctl/collectstatic.py @@ -41,7 +41,8 @@ class CmdCollectStatic(Command): @classmethod def collectstatic(cls, pub, clear=False, link=False): - root_directory_class = pub.root_directory_class + from wcs.root import StaticsDirectory + root_directory_class = StaticsDirectory static_dir = os.path.join(pub.app_dir, 'collectstatic') if clear and os.path.exists(static_dir): shutil.rmtree(static_dir) diff --git a/wcs/qommon/http_response.py b/wcs/qommon/http_response.py index e802b2e..4c2cc3e 100644 --- a/wcs/qommon/http_response.py +++ b/wcs/qommon/http_response.py @@ -60,18 +60,18 @@ class HTTPResponse(quixote.http_response.HTTPResponse): if not self.javascript_scripts: self.javascript_scripts = [] mappings = { - 'jquery.js': '../../static/xstatic/jquery.js', - 'jquery-ui.js': '../../static/xstatic/jquery-ui.js', + 'jquery.js': '../xstatic/jquery.js', + 'jquery-ui.js': '../xstatic/jquery-ui.js', } for script_name in script_names: mapped_script_name = mappings.get(script_name) or script_name if not mapped_script_name in self.javascript_scripts: if script_name == 'qommon.map.js': self.add_javascript(['jquery.js']) - self.add_javascript(['../../leaflet/leaflet.js']) - self.add_css_include('../../leaflet/leaflet.css') + self.add_javascript(['../leaflet/leaflet.js']) + self.add_css_include('../leaflet/leaflet.css') if script_name == 'jquery-ui.js': - self.add_css_include('../../static/xstatic/themes/smoothness/jquery-ui.min.css') + self.add_css_include('../xstatic/themes/smoothness/jquery-ui.min.css') self.javascript_scripts.append(str(mapped_script_name)) if script_name == 'afterjob.js': self.add_javascript_code('var QOMMON_ROOT_URL = "%s";\n' % \ @@ -92,12 +92,7 @@ class HTTPResponse(quixote.http_response.HTTPResponse): if self.javascript_scripts: root_url = get_publisher().get_root_url() + get_publisher().qommon_static_dir s += '\n'.join(['' % ( - root_url, str(x)) for x in self.javascript_scripts - if not x[0] == '/']) - s += '\n' - s += '\n'.join(['' % ( - get_publisher().get_root_url(), x[1:]) for x in self.javascript_scripts - if x[0] == '/']) + root_url, str(x)) for x in self.javascript_scripts]) s += '\n' if self.javascript_code_parts: s += '