diff --git a/horizon/contrib/staticfiles/__init__.py b/horizon/contrib/staticfiles/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/horizon/contrib/staticfiles/finders.py b/horizon/contrib/staticfiles/finders.py new file mode 100644 index 0000000000..6ea9dc39d6 --- /dev/null +++ b/horizon/contrib/staticfiles/finders.py @@ -0,0 +1,39 @@ +# Copyright 2016 IBM Corp. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import os + +from django.apps import apps +from django.contrib.staticfiles.finders import AppDirectoriesFinder + + +class HorizonStaticFinder(AppDirectoriesFinder): + """A static files finder that also looks into the directory of each panel. + """ + + def __init__(self, app_names=None, *args, **kwargs): + super(HorizonStaticFinder, self).__init__(*args, **kwargs) + app_configs = apps.get_app_configs() + for app_config in app_configs: + if 'openstack_dashboard' in app_config.path: + for panel in os.listdir(app_config.path): + panel_path = os.path.join(app_config.path, panel) + if os.path.isdir(panel_path) and panel != self.source_dir: + + # Look for the static folder + static_path = os.path.join(panel_path, self.source_dir) + if os.path.isdir(static_path): + panel_name = app_config.name + panel + app_storage = self.storage_class(static_path) + self.storages[panel_name] = app_storage diff --git a/horizon/test/settings.py b/horizon/test/settings.py index 7f5ab99995..cbcbdf3dc7 100644 --- a/horizon/test/settings.py +++ b/horizon/test/settings.py @@ -134,7 +134,7 @@ COMPRESS_PARSER = 'compressor.parser.HtmlParser' STATICFILES_FINDERS = ( 'django.contrib.staticfiles.finders.FileSystemFinder', - 'django.contrib.staticfiles.finders.AppDirectoriesFinder', + 'horizon.contrib.staticfiles.finders.HorizonStaticFinder', 'compressor.finders.CompressorFinder', ) diff --git a/openstack_dashboard/settings.py b/openstack_dashboard/settings.py index c0e01e2ec4..8e911329c8 100644 --- a/openstack_dashboard/settings.py +++ b/openstack_dashboard/settings.py @@ -143,7 +143,7 @@ TEMPLATE_DIRS = ( STATICFILES_FINDERS = ( 'django.contrib.staticfiles.finders.FileSystemFinder', - 'django.contrib.staticfiles.finders.AppDirectoriesFinder', + 'horizon.contrib.staticfiles.finders.HorizonStaticFinder', 'compressor.finders.CompressorFinder', )