reviewboard.datagrids.sidebar¶
Sidebar item management for datagrids.
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.The datagrid containing this item.
Type: djblets.datagrid.grids.DataGrid
The sidebar containing this item.
Type: Sidebar
The template to use for rendering this item in the sidebar.
The displayed label for the item.
The name of the optional CSS icon to use beside the label.
The datagrid “view” to link to when clicking this item.
This corresponds to the
?view=
parameter passed to the datagrid page.
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.
Additional CSS classes to include for the item.
Initialize the sidebar item.
Parameters: - sidebar (Sidebar) – The sidebar containing this item.
- datagrid (djblets.datagrid.grids.DataGrid) – The datagrid containing this item.
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
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: int
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: bool
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: bool
Render the item.
Returns: The rendered HTML for the item. Return type: django.utils.safestring.SafeText
Return extra context for the render.
Returns: A dictionary of additional template context. By default, this is empty. Return type: dict
Bases:
reviewboard.datagrids.sidebar.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.
Initialize the section.
Parameters: - *args (tuple) – Positional arguments to pass to the parent class.
- **kwargs (dict) – Keyword arguments to pass to the parent class.
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
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: bool
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: dict
Bases:
reviewboard.datagrids.sidebar.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
.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. See
BaseSidebarItem.view_id
for more information. - view_args (unicode, optional) – Keys/values to display in the URL when clicking the item. See
BaseSidebarItem.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 of unicode, optional) – Additional CSS classes to apply to the item.
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
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: int
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.
Initialize the sidebar.
Parameters: - item_classes (list of type) – The list of
BaseSidebarItem
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 registered
BaseSidebarItem.view_id
. - css_classes (list of unicode) – The list of additional CSS classes to apply to the sidebar.
- item_classes (list of type) – The list of
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 an item class from the sidebar.
Parameters: item_cls (type) – The item to remove from the sidebar. This must be a subclass of BaseSidebarItem
.
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
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.Compute any extra state for the sidebar.
This will set
sidebar_items
on the datagrid to a list of instantiated items.Parameters: - *args (tuple) – Additional positional arguments passed to the method.
- **kwargs (dict) – Additional keyword arguments passed to the method.
Returns: The result from the parent method on the datagrid.
Return type: