From af63ac693e5d046b9651d7586748b3e917d48e56 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Tue, 14 Mar 2023 08:39:18 -0400 Subject: [PATCH] Closes #11893: Convert ChangeLogWidget for use with all models --- netbox/extras/constants.py | 6 ++++- netbox/extras/dashboard/widgets.py | 27 +++++++++++++------ .../extras/dashboard/widgets/changelog.html | 4 --- .../extras/dashboard/widgets/objectlist.html | 4 +++ 4 files changed, 28 insertions(+), 13 deletions(-) delete mode 100644 netbox/templates/extras/dashboard/widgets/changelog.html create mode 100644 netbox/templates/extras/dashboard/widgets/objectlist.html diff --git a/netbox/extras/constants.py b/netbox/extras/constants.py index d64f02d6b..d3ac97ae8 100644 --- a/netbox/extras/constants.py +++ b/netbox/extras/constants.py @@ -48,8 +48,12 @@ DEFAULT_DASHBOARD = [ } }, { - 'widget': 'extras.ChangeLogWidget', + 'widget': 'extras.ObjectListWidget', 'width': 12, 'height': 6, + 'title': 'Change Log', + 'config': { + 'model': 'extras.objectchange', + } }, ] diff --git a/netbox/extras/dashboard/widgets.py b/netbox/extras/dashboard/widgets.py index cee8f5f67..85bee2e19 100644 --- a/netbox/extras/dashboard/widgets.py +++ b/netbox/extras/dashboard/widgets.py @@ -7,14 +7,14 @@ from django.utils.translation import gettext as _ from utilities.forms import BootstrapMixin from utilities.templatetags.builtins.filters import render_markdown -from utilities.utils import content_type_identifier, content_type_name +from utilities.utils import content_type_identifier, content_type_name, get_viewname from .utils import register_widget __all__ = ( - 'ChangeLogWidget', 'DashboardWidget', 'NoteWidget', 'ObjectCountsWidget', + 'ObjectListWidget', ) @@ -85,7 +85,7 @@ class NoteWidget(DashboardWidget): @register_widget class ObjectCountsWidget(DashboardWidget): - default_title = _('Objects') + default_title = _('Object Counts') description = _('Display a set of NetBox models and the number of objects created for each type.') template_name = 'extras/dashboard/widgets/objectcounts.html' @@ -108,12 +108,23 @@ class ObjectCountsWidget(DashboardWidget): @register_widget -class ChangeLogWidget(DashboardWidget): - default_title = _('Change Log') - description = _('Display the most recent records from the global change log.') - template_name = 'extras/dashboard/widgets/changelog.html' +class ObjectListWidget(DashboardWidget): + default_title = _('Object List') + description = _('Display an arbitrary list of objects.') + template_name = 'extras/dashboard/widgets/objectlist.html' width = 12 height = 4 + class ConfigForm(BootstrapMixin, forms.Form): + model = forms.ChoiceField( + choices=get_content_type_labels + ) + def render(self, request): - return render_to_string(self.template_name, {}) + app_label, model_name = self.config['model'].split('.') + content_type = ContentType.objects.get_by_natural_key(app_label, model_name) + viewname = get_viewname(content_type.model_class(), action='list') + + return render_to_string(self.template_name, { + 'viewname': viewname, + }) diff --git a/netbox/templates/extras/dashboard/widgets/changelog.html b/netbox/templates/extras/dashboard/widgets/changelog.html deleted file mode 100644 index dfa4dba3f..000000000 --- a/netbox/templates/extras/dashboard/widgets/changelog.html +++ /dev/null @@ -1,4 +0,0 @@ -
diff --git a/netbox/templates/extras/dashboard/widgets/objectlist.html b/netbox/templates/extras/dashboard/widgets/objectlist.html new file mode 100644 index 000000000..e9569396b --- /dev/null +++ b/netbox/templates/extras/dashboard/widgets/objectlist.html @@ -0,0 +1,4 @@ +