Fixing changing WEBROOT from /

There were a few items missed with the patch enabling changing
WEBROOT patch.

First the XStatic files were being unpacked in the wrong directoy
because root_url was not being passed in. This caused 404 errors
when running with a different web root.

This change allows root_url to be passed in on XStatic handling.

Second, STATIC_URL and MEDIA_URL were not using WEBROOT.
These now are built with WEBROOT.

Third, the fa-font-path variable was hard-coded in _variables.scss
to use "/" as the web root.

A webroot variable has been added that can be overridden. Additionally,
a new theme has also been added to change the web root.

Closes-Bug: #1434276
Change-Id: Ifff1c60b3405ce2136d039b8d74da08752e7215c
This commit is contained in:
David Lyle 2015-03-23 08:26:01 -06:00
parent 4fdc42cf63
commit 18dddd97da
8 changed files with 120 additions and 66 deletions

View File

@ -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://<your server>/horizon, you'd set this to ``"/horizon"``.
https://<your server>/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)

View File

@ -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

View File

@ -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

View File

@ -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 */

View File

@ -0,0 +1,3 @@
/* This variable changes the web root of horizon to /dashboard rather
than the default '/' */
$webroot: "/dashboard";

View File

@ -41,57 +41,83 @@ import xstatic.pkg.spin
import xstatic.pkg.termjs
def get_staticfiles_dirs(webroot='/'):
STATICFILES_DIRS = [
('horizon/lib/angular',
xstatic.main.XStatic(xstatic.pkg.angular).base_dir),
xstatic.main.XStatic(xstatic.pkg.angular,
root_url=webroot).base_dir),
('horizon/lib/angular',
xstatic.main.XStatic(xstatic.pkg.angular_bootstrap).base_dir),
xstatic.main.XStatic(xstatic.pkg.angular_bootstrap,
root_url=webroot).base_dir),
('horizon/lib/angular',
xstatic.main.XStatic(xstatic.pkg.angular_irdragndrop).base_dir),
xstatic.main.XStatic(xstatic.pkg.angular_irdragndrop,
root_url=webroot).base_dir),
('horizon/lib/angular',
xstatic.main.XStatic(xstatic.pkg.angular_smart_table).base_dir),
xstatic.main.XStatic(xstatic.pkg.angular_smart_table,
root_url=webroot).base_dir),
('horizon/lib/bootstrap_datepicker',
xstatic.main.XStatic(xstatic.pkg.bootstrap_datepicker).base_dir),
xstatic.main.XStatic(xstatic.pkg.bootstrap_datepicker,
root_url=webroot).base_dir),
('bootstrap',
xstatic.main.XStatic(xstatic.pkg.bootstrap_scss).base_dir),
xstatic.main.XStatic(xstatic.pkg.bootstrap_scss,
root_url=webroot).base_dir),
('horizon/lib',
xstatic.main.XStatic(xstatic.pkg.d3).base_dir),
xstatic.main.XStatic(xstatic.pkg.d3,
root_url=webroot).base_dir),
('horizon/lib',
xstatic.main.XStatic(xstatic.pkg.hogan).base_dir),
xstatic.main.XStatic(xstatic.pkg.hogan,
root_url=webroot).base_dir),
('horizon/lib/font-awesome',
xstatic.main.XStatic(xstatic.pkg.font_awesome).base_dir),
xstatic.main.XStatic(xstatic.pkg.font_awesome,
root_url=webroot).base_dir),
('horizon/lib/jasmine',
xstatic.main.XStatic(xstatic.pkg.jasmine).base_dir),
xstatic.main.XStatic(xstatic.pkg.jasmine,
root_url=webroot).base_dir),
('horizon/lib/jquery',
xstatic.main.XStatic(xstatic.pkg.jquery).base_dir),
xstatic.main.XStatic(xstatic.pkg.jquery,
root_url=webroot).base_dir),
('horizon/lib/jquery',
xstatic.main.XStatic(xstatic.pkg.jquery_migrate).base_dir),
xstatic.main.XStatic(xstatic.pkg.jquery_migrate,
root_url=webroot).base_dir),
('horizon/lib/jquery',
xstatic.main.XStatic(xstatic.pkg.jquery_quicksearch).base_dir),
xstatic.main.XStatic(xstatic.pkg.jquery_quicksearch,
root_url=webroot).base_dir),
('horizon/lib/jquery',
xstatic.main.XStatic(xstatic.pkg.jquery_tablesorter).base_dir),
xstatic.main.XStatic(xstatic.pkg.jquery_tablesorter,
root_url=webroot).base_dir),
('horizon/lib/jsencrypt',
xstatic.main.XStatic(xstatic.pkg.jsencrypt).base_dir),
xstatic.main.XStatic(xstatic.pkg.jsencrypt,
root_url=webroot).base_dir),
('horizon/lib/magic_search',
xstatic.main.XStatic(xstatic.pkg.magic_search).base_dir),
xstatic.main.XStatic(xstatic.pkg.magic_search,
root_url=webroot).base_dir),
('horizon/lib/qunit',
xstatic.main.XStatic(xstatic.pkg.qunit).base_dir),
xstatic.main.XStatic(xstatic.pkg.qunit,
root_url=webroot).base_dir),
('horizon/lib',
xstatic.main.XStatic(xstatic.pkg.rickshaw).base_dir),
xstatic.main.XStatic(xstatic.pkg.rickshaw,
root_url=webroot).base_dir),
('horizon/lib',
xstatic.main.XStatic(xstatic.pkg.spin).base_dir),
xstatic.main.XStatic(xstatic.pkg.spin,
root_url=webroot).base_dir),
('horizon/lib',
xstatic.main.XStatic(xstatic.pkg.termjs).base_dir),
xstatic.main.XStatic(xstatic.pkg.termjs,
root_url=webroot).base_dir),
]
if xstatic.main.XStatic(xstatic.pkg.jquery_ui).version.startswith('1.10.'):
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).base_dir))
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.
# 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))
xstatic.main.XStatic(xstatic.pkg.jquery_ui,
root_url=webroot).base_dir))
return STATICFILES_DIRS

View File

@ -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, ".."))