From 68cea7ac48fefa06b9c1402881f11ade5df59ff2 Mon Sep 17 00:00:00 2001 From: Sourcery AI <> Date: Tue, 7 Feb 2023 05:10:36 +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 e034da6..c17a8d9 100644 --- a/netbox_acls/forms/models.py +++ b/netbox_acls/forms/models.py @@ -239,18 +239,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)