Unifies Horizon conf.

Centralizes all of Horizon's configuration options so that
they're all uniformly accesible from a single place and always
guaranteed to exist.

Implements blueprint unify-config.

Change-Id: I3279b7ccd58302fcff4f0d273f89f282a285c442
This commit is contained in:
Gabriel Hurley
2012-11-17 16:54:48 -08:00
parent 0e328995ec
commit 0065e6642d
12 changed files with 107 additions and 51 deletions

View File

@@ -39,26 +39,13 @@ from django.utils.module_loading import module_has_submodule
from django.utils.translation import ugettext as _
from horizon import loaders
from horizon import conf
from horizon.decorators import require_auth, require_perms, _current_component
LOG = logging.getLogger(__name__)
# Default configuration dictionary. Do not mutate directly. Use copy.copy().
HORIZON_CONFIG = {
# Allow for ordering dashboards; list or tuple if provided.
'dashboards': None,
# Name of a default dashboard; defaults to first alphabetically if None
'default_dashboard': None,
# Default redirect url for users' home
'user_home': settings.LOGIN_REDIRECT_URL,
'exceptions': {'unauthorized': [],
'not_found': [],
'recoverable': []}
}
def _decorate_urlconf(urlpatterns, decorator, *args, **kwargs):
for pattern in urlpatterns:
if getattr(pattern, 'callback', None):
@@ -591,9 +578,7 @@ class Site(Registry, HorizonComponent):
@property
def _conf(self):
conf = copy.copy(HORIZON_CONFIG)
conf.update(getattr(settings, 'HORIZON_CONFIG', {}))
return conf
return conf.HORIZON_CONFIG
@property
def dashboards(self):
@@ -633,11 +618,11 @@ class Site(Registry, HorizonComponent):
""" Returns an ordered tuple of :class:`~horizon.Dashboard` modules.
Orders dashboards according to the ``"dashboards"`` key in
``settings.HORIZON_CONFIG`` or else returns all registered dashboards
``HORIZON_CONFIG`` or else returns all registered dashboards
in alphabetical order.
Any remaining :class:`~horizon.Dashboard` classes registered with
Horizon but not listed in ``settings.HORIZON_CONFIG['dashboards']``
Horizon but not listed in ``HORIZON_CONFIG['dashboards']``
will be appended to the end of the list alphabetically.
"""
if self.dashboards:
@@ -660,7 +645,7 @@ class Site(Registry, HorizonComponent):
def get_default_dashboard(self):
""" Returns the default :class:`~horizon.Dashboard` instance.
If ``"default_dashboard"`` is specified in ``settings.HORIZON_CONFIG``
If ``"default_dashboard"`` is specified in ``HORIZON_CONFIG``
then that dashboard will be returned. If not, the first dashboard
returned by :func:`~horizon.get_dashboards` will be returned.
"""
@@ -680,7 +665,7 @@ class Site(Registry, HorizonComponent):
An alternative function can be supplied to customize this behavior
by specifying a either a URL or a function which returns a URL via
the ``"user_home"`` key in ``settings.HORIZON_CONFIG``. Each of these
the ``"user_home"`` key in ``HORIZON_CONFIG``. Each of these
would be valid::
{"user_home": "/home",} # A URL
@@ -741,9 +726,8 @@ class Site(Registry, HorizonComponent):
dash._autodiscover()
# Allow for override modules
config = getattr(settings, "HORIZON_CONFIG", {})
if config.get("customization_module", None):
customization_module = config["customization_module"]
if self._conf.get("customization_module", None):
customization_module = self._conf["customization_module"]
bits = customization_module.split('.')
mod_name = bits.pop()
package = '.'.join(bits)