@@ -250,22 +250,20 @@ def _validate_acl_type_change(self, acl_type, error_message):
250250 """
251251 Check if Access List has no existing rules before change the Access List's type.
252252 """
253- if self .instance .pk and (
254- (
253+ if self .instance .pk :
254+ error_message ["type" ] = [
255+ "This ACL has ACL rules associated, CANNOT change ACL type." ,
256+ ]
257+ if (
255258 acl_type == ACLTypeChoices .TYPE_EXTENDED
256259 and self .instance .aclstandardrules .exists ()
257- )
258- or (
260+ ):
261+ raise forms .ValidationError (error_message )
262+ if (
259263 acl_type == ACLTypeChoices .TYPE_STANDARD
260264 and self .instance .aclextendedrules .exists ()
261- )
262- ):
263- error_message ["type" ] = [
264- "This ACL has ACL rules associated, CANNOT change ACL type." ,
265- ]
266-
267- if error_message :
268- raise forms .ValidationError (error_message )
265+ ):
266+ raise forms .ValidationError (error_message )
269267
270268 def save (self , * args , ** kwargs ):
271269 """
@@ -406,12 +404,12 @@ def clean(self):
406404 assigned_object_type_id = ContentType .objects .get_for_model (assigned_object ).pk
407405
408406 # Check if the parent host is assigned to the Access List
409- self ._check_if_interface_parent_is_assigned_to_access_list (
407+ self ._validate_if_interface_parent_is_assigned_to_access_list (
410408 cleaned_data .get ("access_list" ), assigned_object_type , assigned_object
411409 )
412410
413411 # Check for duplicate entries in the Access List
414- self ._check_if_interface_already_has_acl_in_direction (
412+ self ._validate_if_interface_already_has_acl_in_direction (
415413 cleaned_data .get ("access_list" ),
416414 assigned_object_id ,
417415 assigned_object_type ,
@@ -446,7 +444,7 @@ def _validate_interface_types(self, interface_types):
446444 elif not interface_types :
447445 raise forms .ValidationError ("No interface or vminterface selected." )
448446
449- def _check_if_interface_parent_is_assigned_to_access_list (
447+ def _validate_if_interface_parent_is_assigned_to_access_list (
450448 self , access_list , assigned_object_type , assigned_object
451449 ):
452450 """
@@ -471,7 +469,7 @@ def _check_if_interface_parent_is_assigned_to_access_list(
471469 }
472470 )
473471
474- def _check_if_interface_already_has_acl_in_direction (
472+ def _validate_if_interface_already_has_acl_in_direction (
475473 self ,
476474 access_list ,
477475 assigned_object_id ,
@@ -573,7 +571,7 @@ def clean(self):
573571 # No need to check for unique_together since there is no usage of GFK
574572
575573 if cleaned_data .get ("action" ) == "remark" :
576- self ._extracted_from_clean_20 (cleaned_data , error_message , "extended" )
574+ self ._validate_acl_rules (cleaned_data , error_message , "extended" )
577575 # Check remark set, but action not set to remark.
578576 elif cleaned_data .get ("remark" ):
579577 error_message ["remark" ] = [ERROR_MESSAGE_REMARK_WITHOUT_ACTION_REMARK ]
@@ -582,7 +580,7 @@ def clean(self):
582580 raise forms .ValidationError (error_message )
583581 return cleaned_data
584582
585- def _extracted_from_clean_20 (self , cleaned_data , error_message , rule_type ):
583+ def _validate_acl_rules (self , cleaned_data , error_message , rule_type ):
586584 """
587585 Validates form inputs before submitting:
588586 - Check if action set to remark, but no remark set.
0 commit comments