Jump to >

reviewboard.admin.widgets

class BaseAdminWidget[source]

The base class for an Administration Dashboard widget.

Widgets appear in the Administration Dashboard and can display useful information on the system, links to other pages, or even fetch data from external sites.

There are a number of built-in widgets, but extensions can provide their own.

Version Added::

4.0: Introduced a a replacement for the legacy Widget class.

widget_id = None[source]

The unique ID of the widget.

name = None[source]

The name of the widget.

This will be shown at the top of the widget.

template_name = 'admin/admin_widget.html'[source]

The name of the template used to render the widget.

css_classes = None[source]

Additional CSS classes to apply to the widget.

If set, this must be a string with a space-separated list of CSS classes.

js_view_class = 'RB.Admin.WidgetView'[source]

The name of the JavaScript view rendering the widget.

js_model_class = 'RB.Admin.Widget'[source]

The name of the JavaScript model handling widget state.

can_render(request)[source]

Return whether the widget can be rendered in the dashboard.

Subclasses can override this to make certain widgets conditional. By default, widgets can always be rendered.

Parameters

request (django.http.HttpRequest) – The HTTP request from the client.

Returns

True, always.

Return type

bool

get_js_model_attrs(request)[source]

Return attributes to pass to the JavaScript model.

These attributes will be passed to the widget model when instantiated.

Parameters

request (django.http.HttpRequest) – The HTTP request from the client.

Returns

The attributes to pass to the model.

Return type

dict

get_js_model_options(request)[source]

Return options to pass to the JavaScript model.

These options will be passed to the widget model when instantiated.

Parameters

request (django.http.HttpRequest) – The HTTP request from the client.

Returns

The options to pass to the model.

Return type

dict

get_js_view_options(request)[source]

Return options to pass to the JavaScript view.

These options will be passed to the widget view when instantiated.

Parameters

request (django.http.HttpRequest) – The HTTP request from the client.

Returns

The options to pass to the view.

Return type

dict

get_extra_context(request)[source]

Return extra context for the template.

Parameters

request (django.http.HttpRequest) – The HTTP request from the client.

Returns

Extra context to pass to the template.

Return type

dict

render(request)[source]

Render the widget to a string.

Parameters

request (django.http.HttpRequest) – The HTTP request from the client.

Returns

The rendered widget HTML.

Return type

django.utils.safestring.SafeText

class Widget[source]

The legacy base class for an Administration Dashboard widget.

Deprecated::

4.0: Widgets should be re-implemented on top of BaseAdminWidget.

property css_classes[source]

The CSS classes for this widget.

This will apply the -is-large or -is-small classes based on the value of size.

render(request)[source]

Render the widget.

This will render the HTML for a widget. It takes care of generating and caching the data, depending on the widget’s needs.

generate_data(request)[source]

Generate data for the widget.

Widgets should override this to provide extra data to pass to the template. This will be available in ‘widget.data’.

If cache_data is True, this data will be cached for the day.

generate_cache_key(request)[source]

Generate a cache key for this widget’s data.

By default, the key takes into account the current day. If the widget is displaying specific to, for example, the user, this should be overridden to include that data in the key.

class AdminWidgetsRegistry[source]

The registry managing all administration dashboard widgets.

register(**kwargs)[source]

Register a new administration widget class.

Parameters

admin_widget_cls (type) – The widget class to register. This must be a subclass of BaseAdminWidget.

Raises
unregister(**kwargs)[source]

Unregister an administration widget class.

Parameters

admin_widget_cls (type) – The widget class to unregister. This must be a subclass of BaseAdminWidget.

Raises

djblets.registries.errors.ItemLookupError – This widget was not registered.

get_widget(widget_id)[source]

Return a widget class with the specified ID.

Parameters

widget_id (unicode) – The ID of the widget to return.

Returns

The subclass of BaseAdminWidget that was registered with the given ID, if found. If the widget was not found, this will return None.

Return type

type

get_defaults()[source]

Return the default widgets for the administration dashboard.

Returns

The list of default widgets.

Return type

list of type

get_sync_num()[source]

Get the sync_num, which is number to sync.

sync_num is number of update and initialized to 1 every day.

class UserActivityWidget[source]

A widget displaying stats on how often users interact with Review Board.

This is displayed as a pie graph, with a legend alongside it breaking down the activity into 1-6 day, 7-29 day, 30-59 day, 60-89 day, and 90+ day ranges.

get_js_model_attrs(request)[source]

Return data for the JavaScript model.

This will calculate the user activity in the various time ranges, and return the data for use in a rendered chart.

Parameters

request (django.http.HttpRequest, unused) – The HTTP request from the client.

Returns

Data for the JavaScript model,.

Return type

dict

class RepositoriesWidget[source]

A widget displaying the most recent repositories.

This widget displays a grid of the most recent repositories and their services/types.

MAX_REPOSITORIES = 8[source]

The maximum number of repositories shown in the widget.

get_extra_context(request)[source]

Return extra context for the template.

Parameters

request (django.http.HttpRequest) – The HTTP request from the client.

Returns

Extra context to pass to the template.

Return type

dict

class ServerCacheWidget[source]

Cache statistics widget.

Displays a list of memcached statistics, if available.

generate_data(request)[source]

Generate data for the widget.

class NewsWidget[source]

A widget displaying the latest Review Board news headlines.

get_js_model_attrs(request)[source]

Return attributes to pass to the JavaScript model.

These contain URLs for the RSS feed and the public news page.

Parameters

request (django.http.HttpRequest) – The HTTP request from the client.

Returns

The attributes to pass to the model.

Return type

dict

dynamic_activity_data(request)[source]

Large database acitivity widget helper.

This method serves as a helper for the activity widget, it’s used with for AJAX requests based on date ranges passed to it.

class ActivityGraphWidget[source]

Detailed database statistics graph widget.

Shows the latest database activity for multiple models in the form of a graph that can be navigated by date.

This widget shows a daily view of creation activity for a list of models. All displayed widget data is computed on demand, rather than up-front during creation of the widget.

init_widgets()[source]

Initialize the widgets subsystem.

This will listen for events in order to manage the widget caches.

register_admin_widget(widget_cls, primary=False)[source]

Register an administration widget.

Deprecated::

4.0: Widgets should be registered on admin_widgets_registry instead.

Parameters
unregister_admin_widget(widget_cls)[source]

Unregister a previously registered administration widget.

admin_widgets_registry = <reviewboard.admin.widgets.AdminWidgetsRegistry object>[source]

The registry of available administration widgets.