mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
#9416: cleanup & widget improvements
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from django import forms
|
||||
from django.urls import reverse_lazy
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from netbox.registry import registry
|
||||
from utilities.forms import BootstrapMixin, add_blank_choice
|
||||
@@ -33,6 +34,7 @@ class DashboardWidgetAddForm(DashboardWidgetForm):
|
||||
'hx-get': reverse_lazy('extras:dashboardwidget_add'),
|
||||
'hx-target': '#widget_add_form',
|
||||
}
|
||||
)
|
||||
),
|
||||
label=_('Widget type')
|
||||
)
|
||||
field_order = ('widget_class', 'title', 'color')
|
||||
|
@@ -54,10 +54,7 @@ def get_dashboard(user):
|
||||
|
||||
def get_default_dashboard():
|
||||
from extras.models import Dashboard
|
||||
dashboard = Dashboard(
|
||||
layout=[],
|
||||
config={}
|
||||
)
|
||||
dashboard = Dashboard()
|
||||
for widget in DEFAULT_DASHBOARD:
|
||||
id = str(uuid.uuid4())
|
||||
dashboard.layout.append({
|
||||
@@ -70,6 +67,7 @@ def get_default_dashboard():
|
||||
dashboard.config[id] = {
|
||||
'class': widget['widget'],
|
||||
'title': widget.get('title'),
|
||||
'color': widget.get('color'),
|
||||
'config': widget.get('config', {}),
|
||||
}
|
||||
|
||||
|
@@ -7,6 +7,7 @@ from django import forms
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.core.cache import cache
|
||||
from django.template.loader import render_to_string
|
||||
from django.urls import NoReverseMatch, reverse
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from utilities.forms import BootstrapMixin
|
||||
@@ -126,14 +127,26 @@ class ObjectListWidget(DashboardWidget):
|
||||
model = forms.ChoiceField(
|
||||
choices=get_content_type_labels
|
||||
)
|
||||
page_size = forms.IntegerField(
|
||||
required=False,
|
||||
min_value=1,
|
||||
max_value=100,
|
||||
help_text=_('The default number of objects to display')
|
||||
)
|
||||
|
||||
def render(self, request):
|
||||
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')
|
||||
try:
|
||||
htmx_url = reverse(viewname)
|
||||
except NoReverseMatch:
|
||||
htmx_url = None
|
||||
|
||||
return render_to_string(self.template_name, {
|
||||
'viewname': viewname,
|
||||
'htmx_url': htmx_url,
|
||||
'page_size': self.config.get('page_size'),
|
||||
})
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user