diff --git a/doc/source/topics/settings.rst b/doc/source/topics/settings.rst index 1ba9269cb4..5121a51805 100755 --- a/doc/source/topics/settings.rst +++ b/doc/source/topics/settings.rst @@ -951,9 +951,27 @@ Specifies the location where the access to the dashboard is configured in the web server. For example, if you're accessing the Dashboard via -https:///horizon, you'd set this to ``"/horizon"``. +https:///dashboard, you would set this to ``"/dashboard/"``. +Additionally, setting the ``"$webroot"`` SCSS variable is required. You +can change this directly in +``"openstack_dasbboard/static/dashboard/scss/_variables.scss"`` or in the +``"_variables.scss"`` file in your custom theme. For more information on +custom themes, see: ``"CUSTOM_THEME_PATH"``. +For your convenience, a custom theme for only setting the web root has been +provided see: ``"/horizon/openstack_dashboard/static/themes/webroot"`` + +.. note:: + + Additional settings may be required in the config files of your webserver + of choice. For example to make ``"/dashboard/"`` the web root in apache, + the ``"sites-available/horizon.conf"`` requires a couple of additional + aliases set:: + + Alias /dashboard/static %HORIZON_DIR%/static + + Alias /dashboard/media %HORIZON_DIR%/openstack_dashboard/static Django Settings (Partial) diff --git a/horizon/test/settings.py b/horizon/test/settings.py index 3b1a60792f..f7bc828d77 100644 --- a/horizon/test/settings.py +++ b/horizon/test/settings.py @@ -22,10 +22,12 @@ import sys import django from django.utils import html_parser -from openstack_dashboard.static_settings import STATICFILES_DIRS # noqa +from openstack_dashboard.static_settings import get_staticfiles_dirs # noqa from horizon.test import patches +STATICFILES_DIRS = get_staticfiles_dirs() + # Patch django.utils.html_parser.HTMLParser as a workaround for bug 1273943 if django.get_version() == '1.4' and sys.version_info[:3] > (2, 7, 3): html_parser.HTMLParser.parse_starttag = patches.parse_starttag_patched diff --git a/openstack_dashboard/settings.py b/openstack_dashboard/settings.py index 4db21495c7..478bfcf7a0 100644 --- a/openstack_dashboard/settings.py +++ b/openstack_dashboard/settings.py @@ -25,7 +25,7 @@ import django from django.utils.translation import ugettext_lazy as _ from openstack_dashboard import exceptions -from openstack_dashboard.static_settings import STATICFILES_DIRS # noqa +from openstack_dashboard.static_settings import get_staticfiles_dirs # noqa warnings.formatwarning = lambda message, category, *args, **kwargs: \ @@ -48,11 +48,6 @@ LOGOUT_URL = None LOGIN_REDIRECT_URL = None -MEDIA_ROOT = os.path.abspath(os.path.join(ROOT_PATH, '..', 'media')) -MEDIA_URL = '/media/' -STATIC_ROOT = os.path.abspath(os.path.join(ROOT_PATH, '..', 'static')) -STATIC_URL = '/static/' - ROOT_URLCONF = 'openstack_dashboard.urls' HORIZON_CONFIG = { @@ -269,11 +264,6 @@ try: except ImportError: logging.warning("No local_settings file found.") -CUSTOM_THEME = os.path.join(ROOT_PATH, CUSTOM_THEME_PATH) -STATICFILES_DIRS.append( - ('custom', CUSTOM_THEME), -) - if not WEBROOT.endswith('/'): WEBROOT += '/' if LOGIN_URL is None: @@ -283,6 +273,16 @@ if LOGOUT_URL is None: if LOGIN_REDIRECT_URL is None: LOGIN_REDIRECT_URL = WEBROOT +MEDIA_ROOT = os.path.abspath(os.path.join(ROOT_PATH, '..', 'media')) +MEDIA_URL = WEBROOT + 'media/' +STATIC_ROOT = os.path.abspath(os.path.join(ROOT_PATH, '..', 'static')) +STATIC_URL = WEBROOT + 'static/' +STATICFILES_DIRS = get_staticfiles_dirs(WEBROOT) + +CUSTOM_THEME = os.path.join(ROOT_PATH, CUSTOM_THEME_PATH) +STATICFILES_DIRS.append( + ('custom', CUSTOM_THEME), +) # Load the pluggable dashboard settings import openstack_dashboard.enabled diff --git a/openstack_dashboard/static/dashboard/scss/_variables.scss b/openstack_dashboard/static/dashboard/scss/_variables.scss index f0e2d2477b..9cf1b4c1c0 100644 --- a/openstack_dashboard/static/dashboard/scss/_variables.scss +++ b/openstack_dashboard/static/dashboard/scss/_variables.scss @@ -2,6 +2,9 @@ to our variables */ @import "/bootstrap/scss/bootstrap/variables"; +/* This variable can be used to change the web root of horizon +default value is already '/' */ +$webroot: "" !default; /* Bootstrap variables overrides */ @@ -62,7 +65,7 @@ $rbrowser-footer-background-color: #f1f1f1; // .table-striped-datatable styles. // Font-awesome path to the icon fonts -$fa-font-path: "/static/horizon/lib/font-awesome/fonts"; +$fa-font-path: $webroot + "/static/horizon/lib/font-awesome/fonts"; /* Charts */ diff --git a/openstack_dashboard/static/themes/webroot/_styles.scss b/openstack_dashboard/static/themes/webroot/_styles.scss new file mode 100644 index 0000000000..e69de29bb2 diff --git a/openstack_dashboard/static/themes/webroot/_variables.scss b/openstack_dashboard/static/themes/webroot/_variables.scss new file mode 100644 index 0000000000..46beac4f5e --- /dev/null +++ b/openstack_dashboard/static/themes/webroot/_variables.scss @@ -0,0 +1,3 @@ +/* This variable changes the web root of horizon to /dashboard rather +than the default '/' */ +$webroot: "/dashboard"; diff --git a/openstack_dashboard/static_settings.py b/openstack_dashboard/static_settings.py index 0679a55c42..127e1bb561 100644 --- a/openstack_dashboard/static_settings.py +++ b/openstack_dashboard/static_settings.py @@ -41,57 +41,83 @@ import xstatic.pkg.spin import xstatic.pkg.termjs -STATICFILES_DIRS = [ - ('horizon/lib/angular', - xstatic.main.XStatic(xstatic.pkg.angular).base_dir), - ('horizon/lib/angular', - xstatic.main.XStatic(xstatic.pkg.angular_bootstrap).base_dir), - ('horizon/lib/angular', - xstatic.main.XStatic(xstatic.pkg.angular_irdragndrop).base_dir), - ('horizon/lib/angular', - xstatic.main.XStatic(xstatic.pkg.angular_smart_table).base_dir), - ('horizon/lib/bootstrap_datepicker', - xstatic.main.XStatic(xstatic.pkg.bootstrap_datepicker).base_dir), - ('bootstrap', - xstatic.main.XStatic(xstatic.pkg.bootstrap_scss).base_dir), - ('horizon/lib', - xstatic.main.XStatic(xstatic.pkg.d3).base_dir), - ('horizon/lib', - xstatic.main.XStatic(xstatic.pkg.hogan).base_dir), - ('horizon/lib/font-awesome', - xstatic.main.XStatic(xstatic.pkg.font_awesome).base_dir), - ('horizon/lib/jasmine', - xstatic.main.XStatic(xstatic.pkg.jasmine).base_dir), - ('horizon/lib/jquery', - xstatic.main.XStatic(xstatic.pkg.jquery).base_dir), - ('horizon/lib/jquery', - xstatic.main.XStatic(xstatic.pkg.jquery_migrate).base_dir), - ('horizon/lib/jquery', - xstatic.main.XStatic(xstatic.pkg.jquery_quicksearch).base_dir), - ('horizon/lib/jquery', - xstatic.main.XStatic(xstatic.pkg.jquery_tablesorter).base_dir), - ('horizon/lib/jsencrypt', - xstatic.main.XStatic(xstatic.pkg.jsencrypt).base_dir), - ('horizon/lib/magic_search', - xstatic.main.XStatic(xstatic.pkg.magic_search).base_dir), - ('horizon/lib/qunit', - xstatic.main.XStatic(xstatic.pkg.qunit).base_dir), - ('horizon/lib', - xstatic.main.XStatic(xstatic.pkg.rickshaw).base_dir), - ('horizon/lib', - xstatic.main.XStatic(xstatic.pkg.spin).base_dir), - ('horizon/lib', - xstatic.main.XStatic(xstatic.pkg.termjs).base_dir), -] +def get_staticfiles_dirs(webroot='/'): + STATICFILES_DIRS = [ + ('horizon/lib/angular', + xstatic.main.XStatic(xstatic.pkg.angular, + root_url=webroot).base_dir), + ('horizon/lib/angular', + xstatic.main.XStatic(xstatic.pkg.angular_bootstrap, + root_url=webroot).base_dir), + ('horizon/lib/angular', + xstatic.main.XStatic(xstatic.pkg.angular_irdragndrop, + root_url=webroot).base_dir), + ('horizon/lib/angular', + xstatic.main.XStatic(xstatic.pkg.angular_smart_table, + root_url=webroot).base_dir), + ('horizon/lib/bootstrap_datepicker', + xstatic.main.XStatic(xstatic.pkg.bootstrap_datepicker, + root_url=webroot).base_dir), + ('bootstrap', + xstatic.main.XStatic(xstatic.pkg.bootstrap_scss, + root_url=webroot).base_dir), + ('horizon/lib', + xstatic.main.XStatic(xstatic.pkg.d3, + root_url=webroot).base_dir), + ('horizon/lib', + xstatic.main.XStatic(xstatic.pkg.hogan, + root_url=webroot).base_dir), + ('horizon/lib/font-awesome', + xstatic.main.XStatic(xstatic.pkg.font_awesome, + root_url=webroot).base_dir), + ('horizon/lib/jasmine', + xstatic.main.XStatic(xstatic.pkg.jasmine, + root_url=webroot).base_dir), + ('horizon/lib/jquery', + xstatic.main.XStatic(xstatic.pkg.jquery, + root_url=webroot).base_dir), + ('horizon/lib/jquery', + xstatic.main.XStatic(xstatic.pkg.jquery_migrate, + root_url=webroot).base_dir), + ('horizon/lib/jquery', + xstatic.main.XStatic(xstatic.pkg.jquery_quicksearch, + root_url=webroot).base_dir), + ('horizon/lib/jquery', + xstatic.main.XStatic(xstatic.pkg.jquery_tablesorter, + root_url=webroot).base_dir), + ('horizon/lib/jsencrypt', + xstatic.main.XStatic(xstatic.pkg.jsencrypt, + root_url=webroot).base_dir), + ('horizon/lib/magic_search', + xstatic.main.XStatic(xstatic.pkg.magic_search, + root_url=webroot).base_dir), + ('horizon/lib/qunit', + xstatic.main.XStatic(xstatic.pkg.qunit, + root_url=webroot).base_dir), + ('horizon/lib', + xstatic.main.XStatic(xstatic.pkg.rickshaw, + root_url=webroot).base_dir), + ('horizon/lib', + xstatic.main.XStatic(xstatic.pkg.spin, + root_url=webroot).base_dir), + ('horizon/lib', + xstatic.main.XStatic(xstatic.pkg.termjs, + root_url=webroot).base_dir), + ] + if xstatic.main.XStatic(xstatic.pkg.jquery_ui, + root_url=webroot).version.startswith('1.10.'): + # The 1.10.x versions already contain the 'ui' directory. + STATICFILES_DIRS.append( + ('horizon/lib/jquery-ui', + xstatic.main.XStatic(xstatic.pkg.jquery_ui, + root_url=webroot).base_dir)) + else: + # Newer versions dropped the directory, add it to keep the path the + # same. + STATICFILES_DIRS.append( + ('horizon/lib/jquery-ui/ui', + xstatic.main.XStatic(xstatic.pkg.jquery_ui, + root_url=webroot).base_dir)) -if xstatic.main.XStatic(xstatic.pkg.jquery_ui).version.startswith('1.10.'): - # The 1.10.x versions already contain the 'ui' directory. - STATICFILES_DIRS.append( - ('horizon/lib/jquery-ui', - xstatic.main.XStatic(xstatic.pkg.jquery_ui).base_dir)) -else: - # Newer versions dropped the directory, add it to keep the path the same. - STATICFILES_DIRS.append( - ('horizon/lib/jquery-ui/ui', - xstatic.main.XStatic(xstatic.pkg.jquery_ui).base_dir)) + return STATICFILES_DIRS diff --git a/openstack_dashboard/test/settings.py b/openstack_dashboard/test/settings.py index 14e95b73ae..db01994c6b 100644 --- a/openstack_dashboard/test/settings.py +++ b/openstack_dashboard/test/settings.py @@ -15,7 +15,9 @@ import os from horizon.test.settings import * # noqa from horizon.utils import secret_key from openstack_dashboard import exceptions +from openstack_dashboard.static_settings import get_staticfiles_dirs # noqa +STATICFILES_DIRS = get_staticfiles_dirs() TEST_DIR = os.path.dirname(os.path.abspath(__file__)) ROOT_PATH = os.path.abspath(os.path.join(TEST_DIR, ".."))