mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-24 17:38:37 -06:00
Closes #11893: Convert ChangeLogWidget for use with all models
This commit is contained in:
parent
6a696d9ed7
commit
af63ac693e
@ -48,8 +48,12 @@ DEFAULT_DASHBOARD = [
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'widget': 'extras.ChangeLogWidget',
|
'widget': 'extras.ObjectListWidget',
|
||||||
'width': 12,
|
'width': 12,
|
||||||
'height': 6,
|
'height': 6,
|
||||||
|
'title': 'Change Log',
|
||||||
|
'config': {
|
||||||
|
'model': 'extras.objectchange',
|
||||||
|
}
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
@ -7,14 +7,14 @@ from django.utils.translation import gettext as _
|
|||||||
|
|
||||||
from utilities.forms import BootstrapMixin
|
from utilities.forms import BootstrapMixin
|
||||||
from utilities.templatetags.builtins.filters import render_markdown
|
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
|
from .utils import register_widget
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'ChangeLogWidget',
|
|
||||||
'DashboardWidget',
|
'DashboardWidget',
|
||||||
'NoteWidget',
|
'NoteWidget',
|
||||||
'ObjectCountsWidget',
|
'ObjectCountsWidget',
|
||||||
|
'ObjectListWidget',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ class NoteWidget(DashboardWidget):
|
|||||||
|
|
||||||
@register_widget
|
@register_widget
|
||||||
class ObjectCountsWidget(DashboardWidget):
|
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.')
|
description = _('Display a set of NetBox models and the number of objects created for each type.')
|
||||||
template_name = 'extras/dashboard/widgets/objectcounts.html'
|
template_name = 'extras/dashboard/widgets/objectcounts.html'
|
||||||
|
|
||||||
@ -108,12 +108,23 @@ class ObjectCountsWidget(DashboardWidget):
|
|||||||
|
|
||||||
|
|
||||||
@register_widget
|
@register_widget
|
||||||
class ChangeLogWidget(DashboardWidget):
|
class ObjectListWidget(DashboardWidget):
|
||||||
default_title = _('Change Log')
|
default_title = _('Object List')
|
||||||
description = _('Display the most recent records from the global change log.')
|
description = _('Display an arbitrary list of objects.')
|
||||||
template_name = 'extras/dashboard/widgets/changelog.html'
|
template_name = 'extras/dashboard/widgets/objectlist.html'
|
||||||
width = 12
|
width = 12
|
||||||
height = 4
|
height = 4
|
||||||
|
|
||||||
|
class ConfigForm(BootstrapMixin, forms.Form):
|
||||||
|
model = forms.ChoiceField(
|
||||||
|
choices=get_content_type_labels
|
||||||
|
)
|
||||||
|
|
||||||
def render(self, request):
|
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,
|
||||||
|
})
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
<div class="htmx-container"
|
|
||||||
hx-get="{% url 'extras:objectchange_list' %}?sort=-time"
|
|
||||||
hx-trigger="load"
|
|
||||||
></div>
|
|
@ -0,0 +1,4 @@
|
|||||||
|
<div class="htmx-container"
|
||||||
|
hx-get="{% url viewname %}"
|
||||||
|
hx-trigger="load"
|
||||||
|
></div>
|
Loading…
Reference in New Issue
Block a user