[ English | português (Brasil) | English (United Kingdom) | Deutsch | Indonesia | 한국어 (대한민국) | русский | नेपाली | français | 中文 (简体, 中国) | Esperanto | español ]
The Horizon Module¶
Horizon ships with a single point of contact for hooking into your project if
you aren’t developing your own Dashboard or
Panel:
import horizon
From there you can access all the key methods you need.
Horizon¶
- horizon.urls¶
The auto-generated URLconf for horizon. Usage:
url(r'', include(horizon.urls)),
- horizon.get_absolute_url()¶
Returns the default URL for Horizon’s URLconf.
The default URL is determined by calling
get_absolute_url()on theDashboardinstance returned byget_default_dashboard().
- horizon.get_user_home(user)¶
Returns the default URL for a particular user.
This method can be used to customize where a user is sent when they log in, etc. By default it returns the value of
get_absolute_url().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 inHORIZON_CONFIG. Each of these would be valid:{"user_home": "/home",} # A URL {"user_home": "my_module.get_user_home",} # Path to a function {"user_home": lambda user: "/" + user.name,} # A function {"user_home": None,} # Will always return the default dashboard
This can be useful if the default dashboard may not be accessible to all users. When user_home is missing from HORIZON_CONFIG, it will default to the settings.LOGIN_REDIRECT_URL value.
- horizon.get_default_dashboard()¶
Returns the default
Dashboardinstance.If
"default_dashboard"is specified inHORIZON_CONFIGthen that dashboard will be returned. If not, the first dashboard returned byget_dashboards()will be returned.
- horizon.get_dashboards()¶
Returns an ordered tuple of
Dashboardmodules.Orders dashboards according to the
"dashboards"key inHORIZON_CONFIGor else returns all registered dashboards in alphabetical order.Any remaining
Dashboardclasses registered with Horizon but not listed inHORIZON_CONFIG['dashboards']will be appended to the end of the list alphabetically.
Dashboard¶
- class horizon.Dashboard(*args, **kwargs)[source]¶
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
Panelmodules, 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
panelsattribute 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 ofPanelGroupclasses 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
nameattributes of thePanelclasses. They should be the names of the Python modules in which thepanel.pyfiles live. This is used for the automatic loading and registration ofPanelclasses much like Django’sModelAdminmachinery.Panel modules must be listed in
panelsin 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
Panelclasses.
- urls¶
Optional path to a URLconf of additional views for this dashboard which are not connected to specific panels. Default:
None.
The
navattribute can be either a boolean value or a callable which accepts aRequestContextobject 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)[source]¶
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.
- get_absolute_url()[source]¶
Returns the default URL for this dashboard.
The default URL is defined as the URL pattern with
name="index"in the URLconf for thePanelspecified bydefault_panel.
- get_panel_group(slug)[source]¶
Returns the specified :class:~horizon.PanelGroup.
Returns None if not registered.
Panel¶
- class horizon.Panel[source]¶
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
Dashboardclass 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.pyliving in the same package as thepanel.pyfile is used. Default:None.
The
navattribute can be either a boolean value or a callable which accepts aRequestContextobject as a single argument to control whether or not this panel should appear in automatically-generated navigation. Default:True.
- index_url_name¶
The
nameargument for the URL pattern which corresponds to the index view for thisPanel. This is the view thatPanel.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
permissionsandallowedthis method is intended to handle settings based conditions rather than user based permission and policy checks. The return value is boolean. If the method returnsTrue, then the panel will be registered and available to user (ifpermissionsandallowedruntime checks are also satisfied). If the method returnsFalse, then the panel will not be registered and will not be available via normal navigation or direct URL access.
Panel Group¶
- class horizon.PanelGroup(dashboard, slug=None, name=None, panels=None)[source]¶
A container for a set of
Panelclasses.When iterated, it will yield each of the
Panelinstances 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.