mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-26 09:16:10 -06:00
Clean up widgets
This commit is contained in:
parent
0bfd986f08
commit
f876e9ed04
@ -7,8 +7,8 @@ DEFAULT_DASHBOARD = [
|
||||
'widget': 'extras.ObjectCountsWidget',
|
||||
'width': 4,
|
||||
'height': 3,
|
||||
'config': {
|
||||
'title': 'IPAM',
|
||||
'config': {
|
||||
'models': [
|
||||
'ipam.Aggregate',
|
||||
'ipam.Prefix',
|
||||
@ -21,8 +21,8 @@ DEFAULT_DASHBOARD = [
|
||||
'widget': 'extras.ObjectCountsWidget',
|
||||
'width': 4,
|
||||
'height': 3,
|
||||
'config': {
|
||||
'title': 'DCIM',
|
||||
'config': {
|
||||
'models': [
|
||||
'dcim.Site',
|
||||
'dcim.Rack',
|
||||
@ -36,7 +36,7 @@ DEFAULT_DASHBOARD = [
|
||||
'width': 4,
|
||||
'height': 3,
|
||||
'config': {
|
||||
'content': 'Welcome to NetBox!'
|
||||
'content': 'Welcome to **NetBox**!'
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -28,7 +28,6 @@ def get_dashboard(user):
|
||||
config = user.config.get('dashboard')
|
||||
else:
|
||||
config = get_default_dashboard_config()
|
||||
print(config)
|
||||
if not user.is_anonymous:
|
||||
user.config.set('dashboard', config, commit=True)
|
||||
|
||||
@ -60,6 +59,7 @@ def get_default_dashboard_config():
|
||||
})
|
||||
config['widgets'][id] = {
|
||||
'class': widget['widget'],
|
||||
'title': widget.get('title'),
|
||||
'config': widget.get('config', {}),
|
||||
}
|
||||
|
||||
|
@ -2,8 +2,10 @@ import uuid
|
||||
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.template.loader import render_to_string
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from utilities.templatetags.builtins.filters import render_markdown
|
||||
from .utils import register_widget
|
||||
|
||||
__all__ = (
|
||||
@ -15,6 +17,8 @@ __all__ = (
|
||||
|
||||
|
||||
class DashboardWidget:
|
||||
title = None
|
||||
description = None
|
||||
width = 4
|
||||
height = 3
|
||||
|
||||
@ -45,14 +49,23 @@ class DashboardWidget:
|
||||
|
||||
@register_widget
|
||||
class StaticContentWidget(DashboardWidget):
|
||||
description = _('Display some arbitrary custom content. Markdown is supported.')
|
||||
default_content = """
|
||||
<div class="d-flex justify-content-center align-items-center" style="height: 100%">
|
||||
<div class="text-center text-muted">Empty</div>
|
||||
</div>
|
||||
"""
|
||||
|
||||
def render(self, request):
|
||||
return self.config.get('content', 'Empty!')
|
||||
if content := self.config.get('content'):
|
||||
return render_markdown(content)
|
||||
return mark_safe(self.default_content)
|
||||
|
||||
|
||||
@register_widget
|
||||
class ObjectCountsWidget(DashboardWidget):
|
||||
title = _('Objects')
|
||||
description = _('Display a set of NetBox models and the number of objects created for each type.')
|
||||
template_name = 'extras/dashboard/widgets/objectcounts.html'
|
||||
|
||||
def render(self, request):
|
||||
@ -70,9 +83,9 @@ class ObjectCountsWidget(DashboardWidget):
|
||||
|
||||
@register_widget
|
||||
class ChangeLogWidget(DashboardWidget):
|
||||
title = _('Change Log')
|
||||
width = 12
|
||||
height = 4
|
||||
title = _('Change log')
|
||||
template_name = 'extras/dashboard/widgets/changelog.html'
|
||||
|
||||
def render(self, request):
|
||||
|
@ -1,7 +1,9 @@
|
||||
{% load helpers %}
|
||||
|
||||
{% if counts %}
|
||||
<div class="list-group list-group-flush">
|
||||
{% for model, count in counts %}
|
||||
<a href="#" class="list-group-item list-group-item-action">
|
||||
<a href="{% url model|viewname:"list" %}" class="list-group-item list-group-item-action">
|
||||
<div class="d-flex w-100 justify-content-between align-items-center">
|
||||
{{ model|meta:"verbose_name_plural"|bettertitle }}
|
||||
<h6 class="mb-1">{{ count }}</h6>
|
||||
|
Loading…
Reference in New Issue
Block a user