reviewboard.datagrids.sidebar¶
Sidebar item management for datagrids.
- class BaseSidebarItem(sidebar, datagrid)[source]¶
Bases:
object
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.
- __init__(sidebar, datagrid)[source]¶
Initialize the sidebar item.
- Parameters:
sidebar (
Sidebar
) – The sidebar containing this item.datagrid (
djblets.datagrid.grids.DataGrid
) – The datagrid containing this item.
- 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:
- 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]¶
Bases:
BaseSidebarItem
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.
- template_name = 'datagrids/sidebar_section.html'[source]¶
The template to use for rendering this item in the sidebar.
- 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:
- is_visible()[source]¶
Return whether the section is visible.
By default, a section is visible if it has any item classes registered. Subclasses can override this to provide more specific logic.
- Returns:
True
if the section is visible.False
if it’s hidden.- Return type:
- get_extra_context()[source]¶
Return extra context for the section.
Subclasses that override this method must call the parent method.
- Returns:
Additional template context for the rendering of the section.
- Return type:
- __annotations__ = {}¶
- class SidebarNavItem(section, label, icon_name=None, view_id=None, view_args=None, count=None, url=None, url_name=None, css_classes=None)[source]¶
Bases:
BaseSidebarItem
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
.- template_name = 'datagrids/sidebar_nav_item.html'[source]¶
The template to use for rendering this item in the sidebar.
- __init__(section, label, icon_name=None, view_id=None, view_args=None, count=None, url=None, url_name=None, css_classes=None)[source]¶
Initialize the item.
- Parameters:
section (
BaseSidebarSection
) – The section that should contain this item.label (
unicode
) – The displayed label for this item.icon_name (
unicode
, optional) – The name of the optional CSS icon to display beside the label.view_id (
unicode
, optional) – The ID of the optional datagrid view to display when clicking the item. SeeBaseSidebarItem.view_id
for more information.view_args (
unicode
, optional) – Keys/values to display in the URL when clicking the item. SeeBaseSidebarItem.view_args
for more information.count (
int
, optional) – The count to display beside the label.url (
unicode
, optional) – The optional URL to navigate to when clicked.url_name (
unicode
, optional) – The optional URL name to resolve and navigate to when clicked.css_classes (
list
ofunicode
, optional) – Additional CSS classes to apply to the item.
- 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:
- get_count()[source]¶
Return the count provided in the constructor.
Subclasses can override this if they need additional logic to compute a count.
- Returns:
The count to display beside the label, or
None
if no count should be shown.- Return type:
- __annotations__ = {}¶
- class Sidebar(item_classes, default_view_id=None, css_classes=[])[source]¶
Bases:
object
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.
- __init__(item_classes, default_view_id=None, css_classes=[])[source]¶
Initialize the sidebar.
- Parameters:
item_classes (
list
oftype
) – The list ofBaseSidebarItem
subclasses to include by default in the sidebar.default_view_id (
unicode
, optional) – The default “view” of the datagrid to display. This corresponds to a registeredBaseSidebarItem.view_id
.css_classes (
list
ofunicode
) – The list of additional CSS classes to apply to the sidebar.
- 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 ofBaseSidebarItem
.
- 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 ofBaseSidebarItem
.
- 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
ofDataGridSidebarItem
- class DataGridSidebarMixin[source]¶
Bases:
object
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.- load_extra_state(*args, **kwargs)[source]¶
Compute any extra state for the sidebar.
This will set
sidebar_items
on the datagrid to a list of instantiated items.
- __annotations__ = {}¶