reviewboard.datagrids.sidebar¶
Sidebar item management for datagrids.
- class BaseSidebarItem(sidebar, datagrid)[source]¶
Base class for an item on the sidebar of a datagrid.
Items can optionally have labels and counts associated with them. Depending on the subclass, it may also be able to nest items.
They may also have custom templates, for more advanced rendering.
See
SidebarNavItem
andBaseSidebarSection
for the common types of sidebar items.- datagrid¶
The datagrid containing this item.
- view_id = None[source]¶
The datagrid “view” to link to when clicking this item.
This corresponds to the
?view=
parameter passed to the datagrid page.
- view_args = None[source]¶
Additional key/values to pass to the URL when clicking this item.
If provided, this must be a dictionary of keys and values for the URL. The keys and values will be automatically URL-encoded.
- get_url()[source]¶
Return the URL used when clicking the item.
By default, this builds a URL to the parent datagrid using the
view_id
andview_args
attributes. If they are not set, then the item won’t be clickable.- Returns
The URL to the dashboard view represented by this item.
- Return type
unicode
- get_count()[source]¶
Return the count shown for this item.
By default, this shows nothing. Subclasses can override to display a count.
- Returns
The count to display beside the item, or
None
if no count should be displayed.- Return type
- is_visible()[source]¶
Return whether the item is visible.
By default, an item is visible. Subclasses can override this to control visibility.
- Returns
True
if the item is visible.False
if it’s hidden.- Return type
- is_active()[source]¶
Return whether the item is currently active.
The item will be active if the current page matches the URL associated with the item.
- Returns
True
if the item represents the active page.False
if it does not.- Return type
- class BaseSidebarSection(*args, **kwargs)[source]¶
Base class for a section of items on the sidebar.
Subclasses can override this to define a section and provide items listed in the section.
Sections can optionally be clickable and display a count.
- get_items()[source]¶
Return the items displayed in this section.
Subclasses must override this and return or yield the items to be displayed.
- Returns
The list of items to display in the section.
- Return type
list of BaseSidebarItem
- class SidebarNavItem(section, label, icon_name=None, view_id=None, view_args=None, count=None, url=None, url_name=None, css_classes=None)[source]¶
A typical navigation link item on the sidebar.
This is the standard type of item added to sections on a sidebar. An item can contain an explicit URL or a resolvable URL name to link to. If not provided, the current datagrid page’s URL will be used along with query arguments built from
view_id
andview_args
.- get_url()[source]¶
Return the URL for the item.
If
url
is set, that URL will be returned directly.If
url_name
is set instead, it will be resolved relative to any Local Site that might be accessed and used as the URL. Note that the URL can’t require any parameters.If not explicit URL or name is provided, the current page is used along with query parameters built from
view_id
andview_args
.- Returns
The URL to navigate to when clicked.
- Return type
unicode
- class Sidebar(item_classes, default_view_id=None, css_classes=[])[source]¶
Provides a sidebar for a datagrid.
A sidebar can have several item classes added to it of various types. These will be instantiated and rendered when rendering the datagrid.
- add_item(item_cls)[source]¶
Add an item class to the sidebar.
- Parameters
item_cls (type) – The item to add to the sidebar. This must be a subclass of
BaseSidebarItem
.
- remove_item(item_cls)[source]¶
Remove an item class from the sidebar.
- Parameters
item_cls (type) – The item to remove from the sidebar. This must be a subclass of
BaseSidebarItem
.
- get_items(datagrid)[source]¶
Instantiate and return all items on the sidebar.
- Parameters
datagrid (djblets.datagrid.grids.DataGrid) – The datagrid instance to associate with each item.
- Returns
The list of instantiated items.
- Return type
list of DataGridSidebarItem
- class DataGridSidebarMixin[source]¶
A mixin for datagrids using a sidebar.
This is meant to be used along with
Sidebar
. It will initialize the sidebar, providing instances of all the items for the template.