5656
5757# Sets a standard error message for ACL rules with an action of remark, but no source is set.
5858error_message_action_remark_source_set = "Action is set to remark, Source CANNOT be set."
59+ # Sets a standard error message for ACL rules with an action of remark, but no destination is set.
60+ error_message_action_remark_destination_set = "Action is set to remark, Destination CANNOT be set."
5961
6062# Sets a standard error message for ACL rules when more than one IP/Host sources are set.
6163error_message_sources_more_than_one = "Only one IP/Host related Source can be specified."
64+ # Sets a standard error message for ACL rules when more than one IP/Host destinations are set.
65+ error_message_destinations_more_than_one = "Only one IP/Host related Destination can be specified."
6266
6367class AccessListForm (NetBoxModelForm ):
6468 """
@@ -736,9 +740,11 @@ def clean(self):
736740 Validates form inputs before submitting:
737741 - Check if action set to remark, but no remark set.
738742 - Check if action set to remark, but source set.
743+ - Check if action set to remark, but destination set.
739744 - Check if action set to remark, but protocol set
740745 - Check remark set, but action not set to remark.
741746 - Check not more than one source is set.
747+ - Check not more than one destination is set.
742748 """
743749 super ().clean ()
744750 cleaned_data = self .cleaned_data
@@ -748,8 +754,9 @@ def clean(self):
748754 remark = cleaned_data .get ("remark" )
749755
750756 sources = ["source_prefix" , "source_iprange" , "source_ipaddress" , "source_aggregate" , "source_service" ]
757+ destinations = ["destination_prefix" , "destination_iprange" , "destination_ipaddress" , "destination_aggregate" , "destination_service" ]
758+
751759 source_ports = cleaned_data .get ("source_ports" )
752- destination_prefix = cleaned_data .get ("destination_prefix" )
753760 destination_ports = cleaned_data .get ("destination_ports" )
754761 protocol = cleaned_data .get ("protocol" )
755762
@@ -760,11 +767,13 @@ def clean(self):
760767 # Check if action set to remark, but source set.
761768 for source in sources :
762769 error_message [source ] = [error_message_action_remark_source_set ]
770+
771+ # Check if action set to remark, but destination set.
772+ for destination in destinations :
773+ error_message [destination ] = [error_message_action_remark_destination_set ]
763774
764775 if source_ports :
765776 error_message ["source_ports" ] = ["Action is set to remark, Source Ports CANNOT be set." ]
766- if destination_prefix :
767- error_message ["destination_prefix" ] = ["Action is set to remark, Destination Prefix CANNOT be set." ]
768777 if destination_ports :
769778 error_message ["destination_ports" ] = ["Action is set to remark, Destination Ports CANNOT be set." ]
770779 if protocol :
@@ -777,5 +786,10 @@ def clean(self):
777786 for source in sources :
778787 error_message [source ] = [error_message_sources_more_than_one ]
779788
789+ # Check not more than one destination is set.
790+ elif sum (bool (cleaned_data .get (destination )) for destination in destinations ) > 1 :
791+ for destination in destinations :
792+ error_message [destination ] = [error_message_destinations_more_than_one ]
793+
780794 if error_message :
781795 raise ValidationError (error_message )
0 commit comments