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.
- 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.
- 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:
- 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:
- 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:
- 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:
- 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:
- 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 AdminWidgetsRegistry[source]¶
Bases:
OrderedRegistry
The registry managing all administration dashboard widgets.
- lookup_attrs: Sequence[str] = ('widget_id',)[source]¶
A list of attributes that items can be looked up by.
- default_errors: RegistryErrorsDict = {'already_registered': 'Could not register the administration widget %(item)s. This widget is already registered or its ID conflicts with another widget.', 'attribute_registered': 'Could not register the administration widget %(item)s: Another widget (%(duplicate)s) is already registered with the same ID.', 'invalid_attribute': '"%(attr_name)s" is not a registered lookup attribute.', 'load_entry_point': 'Could not load entry point %(entry_point)s: %(error)s.', 'missing_attribute': 'Could not register %(item)s: it does not have a "%(attr_name)s" attribute.', 'not_registered': 'No administration widget was found with an ID of "%(attr_value)s".', 'unregister': 'Could not unregister the administration widget %(item)s: This widget has not been registered.'}[source]¶
The default error formatting strings.
If subclasses need to provide additional errors that can be overridden, they should copy
DEFAULT_ERRORS
and set their copy on the subclass as this attribute.- Type:
- register(**kwargs)[source]¶
Register a new administration widget class.
- Parameters:
admin_widget_cls (
type
) – The widget class to register. This must be a subclass ofBaseAdminWidget
.- 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 ofBaseAdminWidget
.- 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 returnNone
.- Return type:
- __annotations__ = {'_by_id': 'Dict[int, RegistryItemType]', '_items': 'Set[RegistryItemType]', '_key_order': 'List[int]', '_populated': 'bool', '_registry': 'Dict[str, Dict[object, RegistryItemType]]', 'already_registered_error_class': 'Type[AlreadyRegisteredError]', 'default_errors': 'RegistryErrorsDict', 'errors': 'RegistryErrorsDict', 'item_name': 'Optional[str]', 'lookup_attrs': 'Sequence[str]', 'lookup_error_class': 'Type[ItemLookupError]'}¶
- __parameters__ = ()¶
- 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:
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.
- name = 'User Activity'[source]¶
The name of the widget.
This will be shown at the top of the widget.
- js_view_class = 'RB.Admin.UserActivityWidgetView'[source]¶
The name of the JavaScript view rendering the widget.
- css_classes = 'rb-c-admin-user-activity-widget'[source]¶
Additional CSS classes to apply to the widget.
If set, this must be a string with a space-separated list of CSS classes.
- 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:
- __annotations__ = {}¶
- class RepositoriesWidget[source]¶
Bases:
BaseAdminWidget
A widget displaying the most recent repositories.
This widget displays a grid of the most recent repositories and their services/types.
- css_classes = 'rb-c-admin-repositories-widget'[source]¶
Additional CSS classes to apply to the widget.
If set, this must be a string with a space-separated list of CSS classes.
- template_name = 'admin/widgets/repositories.html'[source]¶
The name of the template used to render 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:
- __annotations__ = {}¶
- class ServerCacheWidget[source]¶
Bases:
BaseAdminWidget
Cache statistics widget.
Displays a list of memcached statistics, if available.
- template_name = 'admin/widgets/server_cache.html'[source]¶
The name of the template used to render 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:
- __annotations__ = {}¶
- class NewsWidget[source]¶
Bases:
BaseAdminWidget
A widget displaying the latest Review Board news headlines.
- name = 'Review Board News'[source]¶
The name of the widget.
This will be shown at the top of the widget.
- css_classes = 'rb-c-admin-news-widget'[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.NewsWidgetView'[source]¶
The name of the JavaScript view rendering the widget.
- js_model_class = 'RB.Admin.NewsWidget'[source]¶
The name of the JavaScript model handling widget state.
- 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:
- __annotations__ = {}¶
- dynamic_activity_data(request)[source]¶
Large database activity 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:
BaseAdminWidget
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.
- name = 'Review Board Activity'[source]¶
The name of the widget.
This will be shown at the top of the widget.
- js_model_class = 'RB.Admin.ServerActivityWidget'[source]¶
The name of the JavaScript model handling widget state.
- js_view_class = 'RB.Admin.ServerActivityWidgetView'[source]¶
The name of the JavaScript view rendering the widget.
- css_classes = 'rb-c-admin-server-activity-widget'[source]¶
Additional CSS classes to apply to the widget.
If set, this must be a string with a space-separated list of CSS classes.
- __annotations__ = {}¶