From 3dea3ffe050a2d261677dd3dc66e1ac0e32fb692 Mon Sep 17 00:00:00 2001 From: Peter Eckel Date: Fri, 9 Aug 2024 09:49:20 +0000 Subject: [PATCH 1/3] Do not omit "False" values from the request URL for cloned fields --- netbox/utilities/querydict.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netbox/utilities/querydict.py b/netbox/utilities/querydict.py index 78395758af..dbe2e42818 100644 --- a/netbox/utilities/querydict.py +++ b/netbox/utilities/querydict.py @@ -55,7 +55,7 @@ def prepare_cloned_fields(instance): for key, value in attrs.items(): if type(value) in (list, tuple): params.extend([(key, v) for v in value]) - elif value is not False and value is not None: + elif value is not None: params.append((key, value)) else: params.append((key, '')) From e8a5fa32ce1709726c04e6f150f80b2a88bf0f38 Mon Sep 17 00:00:00 2001 From: Peter Eckel Date: Sun, 11 Aug 2024 12:51:20 +0000 Subject: [PATCH 2/3] Limit the fix to custom field data --- netbox/utilities/querydict.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netbox/utilities/querydict.py b/netbox/utilities/querydict.py index dbe2e42818..b1cb524f6a 100644 --- a/netbox/utilities/querydict.py +++ b/netbox/utilities/querydict.py @@ -55,7 +55,7 @@ def prepare_cloned_fields(instance): for key, value in attrs.items(): if type(value) in (list, tuple): params.extend([(key, v) for v in value]) - elif value is not None: + elif value is not None and (key.startswith('cf_') or value is not False): params.append((key, value)) else: params.append((key, '')) From ce7343c279b48e460d7e93cac71aa52a9a819257 Mon Sep 17 00:00:00 2001 From: Peter Eckel Date: Tue, 20 Aug 2024 08:56:54 +0000 Subject: [PATCH 3/3] Properly handle "False" as a text parameter when initialising NetBoxModelForm --- netbox/netbox/forms/base.py | 10 ++++++++++ netbox/utilities/querydict.py | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/netbox/netbox/forms/base.py b/netbox/netbox/forms/base.py index d59f61ef9b..9befe07c73 100644 --- a/netbox/netbox/forms/base.py +++ b/netbox/netbox/forms/base.py @@ -1,6 +1,7 @@ import json from django import forms +from django.forms.fields import BooleanField, NullBooleanField from django.contrib.contenttypes.models import ContentType from django.db.models import Q from django.utils.translation import gettext_lazy as _ @@ -31,6 +32,15 @@ class NetBoxModelForm(CheckLastUpdatedMixin, CustomFieldsMixin, TagsMixin, forms """ fieldsets = () + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + for key, value in self.initial.items(): + if key not in self.fields: + continue + if isinstance(self.fields[key], (BooleanField, NullBooleanField)) and self.initial[key] == "False": + self.initial[key] = False + def _get_content_type(self): return ContentType.objects.get_for_model(self._meta.model) diff --git a/netbox/utilities/querydict.py b/netbox/utilities/querydict.py index b1cb524f6a..dbe2e42818 100644 --- a/netbox/utilities/querydict.py +++ b/netbox/utilities/querydict.py @@ -55,7 +55,7 @@ def prepare_cloned_fields(instance): for key, value in attrs.items(): if type(value) in (list, tuple): params.extend([(key, v) for v in value]) - elif value is not None and (key.startswith('cf_') or value is not False): + elif value is not None: params.append((key, value)) else: params.append((key, ''))