Widgets: Simple Data Widgets

While django-controlcenter excels at displaying data from Django models, it also supports widgets for showing plain Python data like lists and dictionaries. This is useful for displaying application settings, health check statuses, or links to external services.

These widgets are located in controlcenter.widgets.contrib.simple.

Data Items

For simple text display, you can use strings. For richer content, you can use a dictionary or the DataItem namedtuple. A DataItem can hold:

  • label: The text to display.
  • url: If provided, the label becomes a hyperlink.
  • help_text: Additional descriptive text displayed below the label.
from controlcenter.widgets.contrib.simple import DataItem

# A simple string
'My Value'

# A dictionary for a link
{'label': 'Datadog Dashboard', 'url': 'https://datadog.example.com'}

# A DataItem with help text
DataItem(label='Healthcheck', 
         url='/healthcheck/', 
         help_text='Reports status of external dependencies')

ValueList

The ValueList widget renders a single-column list of items. Override the get_data() method to return a list of strings, dictionaries, or DataItem objects.

from controlcenter.widgets.contrib import simple as widgets
from controlcenter.widgets.contrib.simple import DataItem

class DebuggingEndpointsWidget(widgets.ValueList):
    title = 'Debugging Endpoints'
    subtitle = 'Links for debugging application issues'

    def get_data(self):
        return [
            # A dictionary defining a display label and a url.
            {'label': 'Datadog Dashboard', 'url': 'https://example.com'},
            # DataItem can be used as an alternative to dictionaries.
            DataItem(label='Healthcheck', url='https://example.com',
                     help_text='Healthcheck report for external dependencies'),
        ]

KeyValueList

The KeyValueList widget renders a two-column table of key-value pairs. Override get_data() to return a dictionary.

The keys and values can be strings, dictionaries, or DataItem objects.

Note: Since dictionary keys must be hashable, you must use DataItem if you want a key to be a link or have help text.

from controlcenter.widgets.contrib import simple as widgets
from controlcenter.widgets.contrib.simple import DataItem
from django.conf import settings

class AppInfoWidget(widgets.KeyValueList):
    title = 'Application Information'

    def get_data(self):
        return {
            # A simple key-value pair
            'Language code': settings.LANGUAGE_CODE,
            # A value with a link
            'Default timezone': {
                'label': settings.TIME_ZONE,
                'url': 'https://docs.djangoproject.com/en/stable/topics/i18n/timezones/',
            },
            # A key with a link (requires DataItem)
            DataItem(
                label='Debug Mode',
                url='https://docs.djangoproject.com/en/stable/ref/settings/#debug'
            ): settings.DEBUG,
        }