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:
@@ -67,12 +67,16 @@ class ExportForm(forms.Form):
|
||||
|
||||
def __init__(self, *args, scope=None, **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()]
|
||||
if scope is not None:
|
||||
role_ids = scope.devices().values("role")
|
||||
roles = DeviceRole.objects.filter(pk__in=role_ids).order_by("name")
|
||||
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["subtitle"].initial = f"{scope.label}: {scope.obj}"
|
||||
if not get_plugin_config("netbox_customer_export", "allow_secrets"):
|
||||
|
||||
Reference in New Issue
Block a user