Skip to content

Commit 7bdf349

Browse files
committed
fix(forms): Remove unnecessary prefill_source logic
Eliminates redundant `prefill_source` logic from ACL forms. Simplifies conditions for resetting `source` and `destination` fields during initialization, improving code clarity and maintainability.
1 parent c403313 commit 7bdf349

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

netbox_acls/forms/models.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -579,10 +579,6 @@ def __init__(self, *args, **kwargs) -> None:
579579
# Initialize the source object field
580580
initial["source"] = instance.source
581581

582-
# Check if "comments" is absent, indicating a request with custom
583-
# GET parameters for prefilling of the form field "source".
584-
prefill_source = "comments" not in initial
585-
586582
kwargs["initial"] = initial
587583

588584
super().__init__(*args, **kwargs)
@@ -602,7 +598,7 @@ def __init__(self, *args, **kwargs) -> None:
602598
pass
603599

604600
# Clears the source field if the selected type changes
605-
if self.instance and source_type_id != self.instance.source_type_id and not prefill_source:
601+
if self.instance and self.instance.pk and source_type_id != self.instance.source_type_id:
606602
self.initial["source"] = None
607603

608604
def clean(self):
@@ -744,10 +740,6 @@ def __init__(self, *args, **kwargs) -> None:
744740
# Initialize the destination object field
745741
initial["destination"] = instance.destination
746742

747-
# Check if "comments" is absent, indicating a request with custom
748-
# GET parameters for prefilling of the form field "source".
749-
prefill_source = "comments" not in initial
750-
751743
kwargs["initial"] = initial
752744

753745
super().__init__(*args, **kwargs)
@@ -768,7 +760,7 @@ def __init__(self, *args, **kwargs) -> None:
768760
pass
769761

770762
# Clears the source field if the selected type changes
771-
if self.instance and source_type_id != self.instance.source_type_id and not prefill_source:
763+
if self.instance and self.instance.pk and source_type_id != self.instance.source_type_id:
772764
self.initial["source"] = None
773765

774766
# Destination
@@ -787,7 +779,7 @@ def __init__(self, *args, **kwargs) -> None:
787779
pass
788780

789781
# Clears the destination field if the selected type changes
790-
if self.instance and destination_type_id != self.instance.destination_type_id and not prefill_source:
782+
if self.instance and self.instance.pk and destination_type_id != self.instance.destination_type_id:
791783
self.initial["destination"] = None
792784

793785
def clean(self):

0 commit comments

Comments
 (0)