Jump to >

reviewboard.admin.widgets

class BaseAdminWidget[source]

Bases: object

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 = u'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 = u'RB.Admin.WidgetView'[source]

The name of the JavaScript view rendering the widget.

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

The name of the JavaScript model handling widget state.

__init__()[source]

Initialize the widget.

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]

Bases: reviewboard.admin.widgets.BaseAdminWidget

The legacy base class for an Administration Dashboard widget.

Deprecated::
4.0: Widgets should be re-implemented on top of BaseAdminWidget.
SMALL = u'small'[source]
LARGE = u'large'[source]
widget_id = None[source]
title = None[source]
size = u'small'[source]
template = None[source]
actions = [][source]
has_data = True[source]
cache_data = True[source]
template_name = u'admin/legacy_admin_widget.html'[source]
__init__()[source]

Initialize the widget.

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]

Bases: djblets.registries.registry.OrderedRegistry

The registry managing all administration dashboard widgets.

lookup_attrs = (u'widget_id',)[source]
default_errors = {u'already_registered': u'Could not register the administration widget %(item)s. This widget is already registered or its ID conficts with another widget.', u'attribute_registered': u'Could not register the administration widget %(item)s: Another widget (%(duplicate)s) is already registered with the same ID.', u'invalid_attribute': u'"%(attr_name)s" is not a registered lookup attribute.', u'load_entry_point': u'Could not load entry point %(entry_point)s: %(error)s.', u'missing_attribute': u'Could not register %(item)s: it does not have a "%(attr_name)s" attribute.', u'not_registered': u'No administration widget was found with an ID of "%(attr_value)s".', u'unregister': u'Could not unregister the administration widget %(item)s: This widget has not been registered.'}[source]
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:
  • djblets.registries.errors.RegistrationError – The BaseAdminWidget.widget_id value is missing on the class.
  • djblets.registries.errors.AlreadyRegisteredError – This widget, or another with the same ID, was already registered.
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]

Bases: reviewboard.admin.widgets.BaseAdminWidget

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.

widget_id = u'user-activity-widget'[source]
name = u'User Activity'[source]
js_view_class = u'RB.Admin.UserActivityWidgetView'[source]
css_classes = u'rb-c-admin-user-activity-widget'[source]
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]

Bases: reviewboard.admin.widgets.BaseAdminWidget

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.

widget_id = u'repositories-widget'[source]
name = u'Repositories'[source]
css_classes = u'rb-c-admin-repositories-widget'[source]
template_name = u'admin/widgets/repositories.html'[source]
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]

Bases: reviewboard.admin.widgets.Widget

Cache statistics widget.

Displays a list of memcached statistics, if available.

widget_id = u'server-cache-widget'[source]
title = u'Server Cache'[source]
template = u'admin/widgets/w-server-cache.html'[source]
cache_data = False[source]
generate_data(request)[source]

Generate data for the widget.

class NewsWidget[source]

Bases: reviewboard.admin.widgets.BaseAdminWidget

A widget displaying the latest Review Board news headlines.

widget_id = u'news'[source]
name = u'Review Board News'[source]
css_classes = u'rb-c-admin-news-widget'[source]
js_view_class = u'RB.Admin.NewsWidgetView'[source]
js_model_class = u'RB.Admin.NewsWidget'[source]
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]

Bases: reviewboard.admin.widgets.Widget

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.

widget_id = u'activity-graph-widget'[source]
title = u'Review Board Activity'[source]
size = u'large'[source]
template = u'admin/widgets/w-stats-large.html'[source]
actions = [{u'classes': u'js-action-prev', u'id': u'db-stats-graph-prev', u'label': u'<'}, {u'classes': u'js-action-next', u'id': u'db-stats-graph-next', u'label': u'>'}, {u'classes': u'js-action-toggle js-stat-reviews js-is-active', u'label': u'Reviews'}, {u'classes': u'js-action-toggle js-stat-comments js-is-active', u'label': u'Comments'}, {u'classes': u'js-action-toggle js-stat-review-requests js-is-active', u'label': u'Review Requests'}, {u'classes': u'js-action-toggle js-stat-changes js-is-active', u'label': u'Changes'}][source]
has_data = False[source]
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.