From 2338db43a3b0ffc91433ad6c4abcdb9b30f07430 Mon Sep 17 00:00:00 2001 From: Sourcery AI <> Date: Fri, 3 Feb 2023 14:38:54 +0000 Subject: [PATCH] 'Refactored by Sourcery' --- netbox_acls/forms/models.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/netbox_acls/forms/models.py b/netbox_acls/forms/models.py index 3a1d4cd..6b87e6a 100644 --- a/netbox_acls/forms/models.py +++ b/netbox_acls/forms/models.py @@ -230,18 +230,20 @@ def clean(self): host_type: [error_same_acl_name], "name": [error_same_acl_name], } - if self.instance.pk: - # Check if Access List has no existing rules before change the Access List's type. - if ( + if ( + self.instance.pk + and ( acl_type == ACLTypeChoices.TYPE_EXTENDED and self.instance.aclstandardrules.exists() - ) or ( + ) + or ( acl_type == ACLTypeChoices.TYPE_STANDARD and self.instance.aclextendedrules.exists() - ): - error_message["type"] = [ - "This ACL has ACL rules associated, CANNOT change ACL type.", - ] + ) + ): + error_message["type"] = [ + "This ACL has ACL rules associated, CANNOT change ACL type.", + ] if error_message: raise forms.ValidationError(error_message)