The horizon Module

The Horizon interface.

Contains the core Horizon classes–Dashboard and horizon.Panel–the dynamic URLconf for Horizon, and common interface methods like register() and unregister().

class horizon.Dashboard(*args, **kwargs)

Bases: horizon.base.Registry, horizon.base.HorizonComponent

A base class for defining Horizon dashboards.

All Horizon dashboards should extend from this base class. It provides the appropriate hooks for automatic discovery of Panel modules, automatically constructing URLconfs, and providing permission-based access control.

name

The name of the dashboard. This will be displayed in the auto-generated navigation and various other places. Default: ''.

slug

A unique “short name” for the dashboard. The slug is used as a component of the URL path for the dashboard. Default: ''.

panels

The panels attribute can be either a flat list containing the name of each panel module which should be loaded as part of this dashboard, or a list of PanelGroup classes which define groups of panels as in the following example:

class SystemPanels(horizon.PanelGroup):
    slug = "syspanel"
    name = _("System")
    panels = ('overview', 'instances', ...)

class Syspanel(horizon.Dashboard):
    panels = (SystemPanels,)

Automatically generated navigation will use the order of the modules in this attribute.

Default: [].

Warning

The values for this attribute should not correspond to the name attributes of the Panel classes. They should be the names of the Python modules in which the panel.py files live. This is used for the automatic loading and registration of Panel classes much like Django’s ModelAdmin machinery.

Panel modules must be listed in panels in order to be discovered by the automatic registration mechanism.

default_panel

The name of the panel which should be treated as the default panel for the dashboard, i.e. when you visit the root URL for this dashboard, that’s the panel that is displayed. Default: None.

permissions

A list of permission names, all of which a user must possess in order to access any panel registered with this dashboard. This attribute is combined cumulatively with any permissions required on individual Panel classes.

urls

Optional path to a URLconf of additional views for this dashboard which are not connected to specific panels. Default: None.

nav
nav(context)

The nav attribute can be either boolean value or a callable which accepts a RequestContext object as a single argument to control whether or not this dashboard should appear in automatically-generated navigation. Default: True.

public

Boolean value to determine whether this dashboard can be viewed without being logged in. Defaults to False.

allowed(context)

Checks for role based access for this dashboard.

Checks for access to any panels in the dashboard and of the dashboard itself.

This method should be overridden to return the result of any policy checks required for the user to access this dashboard when more complex checks are required.

default_panel = None
get_absolute_url()

Returns the default URL for this dashboard.

The default URL is defined as the URL pattern with name="index" in the URLconf for the Panel specified by default_panel.

get_panel(panel)

Returns the specified Panel instance registered with this dashboard.

get_panel_group(slug)

Returns the specified :class:~horizon.PanelGroup or None if not registered

get_panel_groups()
get_panels()

Returns the Panel instances registered with this dashboard in order, without any panel groupings.

name = ''
nav = True
panels = []
public = False
classmethod register(panel)

Registers a Panel with this dashboard.

slug = ''
classmethod unregister(panel)

Unregisters a Panel from this dashboard.

urls = None
class horizon.Panel

Bases: horizon.base.HorizonComponent

A base class for defining Horizon dashboard panels.

All Horizon dashboard panels should extend from this class. It provides the appropriate hooks for automatically constructing URLconfs, and providing permission-based access control.

name

The name of the panel. This will be displayed in the auto-generated navigation and various other places. Default: ''.

slug

A unique “short name” for the panel. The slug is used as a component of the URL path for the panel. Default: ''.

permissions

A list of permission names, all of which a user must possess in order to access any view associated with this panel. This attribute is combined cumulatively with any permissions required on the Dashboard class with which it is registered.

urls

Path to a URLconf of views for this panel using dotted Python notation. If no value is specified, a file called urls.py living in the same package as the panel.py file is used. Default: None.

nav
nav(context)

The nav attribute can be either boolean value or a callable which accepts a RequestContext object as a single argument to control whether or not this panel should appear in automatically-generated navigation. Default: True.

index_url_name

The name argument for the URL pattern which corresponds to the index view for this Panel. This is the view that Panel.get_absolute_url() will attempt to reverse.

static can_register()

This optional static method can be used to specify conditions that need to be satisfied to load this panel. Unlike permissions and allowed this method is intended to handle settings based conditions rather than user based permission and policy checks. The return value is boolean. If the method returns True, then the panel will be registered and available to user (if permissions and allowed runtime checks are also satisfied). If the method returns False, then the panel will not be registered and will not be available via normal navigation or direct URL access.

get_absolute_url()

Returns the default URL for this panel.

The default URL is defined as the URL pattern with name="index" in the URLconf for this panel.

index_url_name = 'index'
name = ''
nav = True
slug = ''
urls = None
class horizon.PanelGroup(dashboard, slug=None, name=None, panels=None)

Bases: object

A container for a set of Panel classes.

When iterated, it will yield each of the Panel instances it contains.

slug

A unique string to identify this panel group. Required.

name

A user-friendly name which will be used as the group heading in places such as the navigation. Default: None.

panels

A list of panel module names which should be contained within this grouping.

Previous topic

The horizon.version Module

Next topic

The horizon.loaders Module

Project Source

This Page