Jump to >

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 and BaseSidebarSection for the common types of sidebar items.

datagrid

djblets.datagrid.grids.DataGrid – The datagrid containing this item.

sidebar

Sidebar – The sidebar containing this item.

template_name = None[source]

The template to use for rendering this item in the sidebar.

label = None[source]

The displayed label for the item.

icon_name = None[source]

The name of the optional CSS icon to use beside the label.

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.

css_classes = None[source]

Additional CSS classes to include for the item.

__init__(sidebar, datagrid)[source]

Initialize the sidebar item.

Parameters:
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 and view_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:int
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:bool
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:bool
render()[source]

Render the item.

Returns:The rendered HTML for the item.
Return type:django.utils.safestring.SafeText
get_extra_context()[source]

Return extra context for the render.

Returns:A dictionary of additional template context. By default, this is empty.
Return type:dict
class BaseSidebarSection(*args, **kwargs)[source]

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.

template_name = u'datagrids/sidebar_section.html'[source]
__init__(*args, **kwargs)[source]

Initialize the section.

Parameters:
  • *args (tuple) – Positional arguments to pass to the parent class.
  • **kwargs (dict) – Keyword arguments to pass to the parent class.
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
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:bool
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:dict
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: 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 and view_args.

template_name = u'datagrids/sidebar_nav_item.html'[source]
__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. 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.
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 and view_args.

Returns:The URL to navigate to when clicked.
Return type:unicode
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:int
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 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.
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]

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.

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:

object