fix: render export form checkboxes as real checkboxes

The widgets lacked the form-check-input class, so NetBox's CSS showed
them as empty text inputs with no visible checked state. Also pass role
PKs as initial value so all device roles in scope are preselected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-23 13:07:44 +02:00
co-authored by Claude Opus 5.5
parent e7f25904fc
commit 0719f42cb3
+5 -1
View File
@@ -67,12 +67,16 @@ class ExportForm(forms.Form):
def __init__(self, *args, scope=None, **kwargs): def __init__(self, *args, scope=None, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
# Ohne diese Klasse stellt NetBox' CSS die Checkboxen als leere Eingabefelder dar
for field in self.fields.values():
if isinstance(field.widget, (forms.CheckboxInput, forms.CheckboxSelectMultiple)):
field.widget.attrs["class"] = "form-check-input"
self.fields["branding"].choices = [(k, b["name"]) for k, b in get_brandings().items()] self.fields["branding"].choices = [(k, b["name"]) for k, b in get_brandings().items()]
if scope is not None: if scope is not None:
role_ids = scope.devices().values("role") role_ids = scope.devices().values("role")
roles = DeviceRole.objects.filter(pk__in=role_ids).order_by("name") roles = DeviceRole.objects.filter(pk__in=role_ids).order_by("name")
self.fields["roles"].queryset = roles self.fields["roles"].queryset = roles
self.fields["roles"].initial = list(roles) self.fields["roles"].initial = [r.pk for r in roles]
self.fields["title"].initial = f"Netzwerkdokumentation {scope.obj}" self.fields["title"].initial = f"Netzwerkdokumentation {scope.obj}"
self.fields["subtitle"].initial = f"{scope.label}: {scope.obj}" self.fields["subtitle"].initial = f"{scope.label}: {scope.obj}"
if not get_plugin_config("netbox_customer_export", "allow_secrets"): if not get_plugin_config("netbox_customer_export", "allow_secrets"):