From b2d7322e56197e7d8b324e1335bbe544fd2ee5d3 Mon Sep 17 00:00:00 2001 From: Thai Tran Date: Wed, 10 Feb 2016 13:48:31 -0800 Subject: [PATCH] Panel static finder We are only able to store static content at the dashboard (app) level. This forces us to store all of our statics under the dashboard's static folder. This patch introduces a panel static finder. Django's static finder will now find files inside the panel's static folder as well. This is more inline with what we have today for python plugins. Change-Id: I2bb3f78abf8854dbad8f1697d942f94d36014d41 Closes-Bug: #1544295 --- horizon/contrib/staticfiles/__init__.py | 0 horizon/contrib/staticfiles/finders.py | 39 +++++++++++++++++++++++++ horizon/test/settings.py | 2 +- openstack_dashboard/settings.py | 2 +- 4 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 horizon/contrib/staticfiles/__init__.py create mode 100644 horizon/contrib/staticfiles/finders.py 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', )