1818 ACLInterfaceAssignment ,
1919 ACLStandardRule ,
2020)
21- from .nested_serializers import NestedAccessListSerializer
2221
2322__all__ = [
2423 "AccessListSerializer" ,
3332error_message_action_remark_source_prefix_set = "Action is set to remark, Source Prefix CANNOT be set."
3433# Sets a standard error message for ACL rules with an action not set to remark, but no remark is set.
3534error_message_remark_without_action_remark = "CANNOT set remark unless action is set to remark."
36- # Sets a standard error message for ACL rules no associated to an ACL of the same type.
35+ # Sets a standard error message for ACL rules no associated with an ACL of the same type.
3736error_message_acl_type = "Provided parent Access List is not of right type."
3837
3938
4039class AccessListSerializer (NetBoxModelSerializer ):
4140 """
42- Defines the serializer for the django AccessList model & associates it to a view.
41+ Defines the serializer for the django AccessList model and associates it with a view.
4342 """
4443
4544 url = serializers .HyperlinkedIdentityField (
@@ -106,13 +105,13 @@ def validate(self, data):
106105
107106class ACLInterfaceAssignmentSerializer (NetBoxModelSerializer ):
108107 """
109- Defines the serializer for the django ACLInterfaceAssignment model & associates it to a view.
108+ Defines the serializer for the django ACLInterfaceAssignment model and associates it with a view.
110109 """
111110
112111 url = serializers .HyperlinkedIdentityField (
113112 view_name = "plugins-api:netbox_acls-api:aclinterfaceassignment-detail" ,
114113 )
115- access_list = NestedAccessListSerializer ( )
114+ access_list = AccessListSerializer ( nested = True , required = True )
116115 assigned_object_type = ContentTypeField (
117116 queryset = ContentType .objects .filter (ACL_INTERFACE_ASSIGNMENT_MODELS ),
118117 )
@@ -142,9 +141,7 @@ class Meta:
142141
143142 @extend_schema_field (serializers .DictField ())
144143 def get_assigned_object (self , obj ):
145- serializer = get_serializer_for_model (
146- obj .assigned_object
147- )
144+ serializer = get_serializer_for_model (obj .assigned_object )
148145 context = {"request" : self .context ["request" ]}
149146 return serializer (obj .assigned_object , nested = True , context = context ).data
150147
@@ -160,7 +157,9 @@ def validate(self, data):
160157 if data ["assigned_object_type" ].model == "interface" :
161158 interface_host = data ["assigned_object_type" ].get_object_for_this_type (id = data ["assigned_object_id" ]).device
162159 elif data ["assigned_object_type" ].model == "vminterface" :
163- interface_host = data ["assigned_object_type" ].get_object_for_this_type (id = data ["assigned_object_id" ]).virtual_machine
160+ interface_host = (
161+ data ["assigned_object_type" ].get_object_for_this_type (id = data ["assigned_object_id" ]).virtual_machine
162+ )
164163 else :
165164 interface_host = None
166165 # Check that the associated interface's parent host has the selected ACL defined.
@@ -177,18 +176,18 @@ def validate(self, data):
177176
178177class ACLStandardRuleSerializer (NetBoxModelSerializer ):
179178 """
180- Defines the serializer for the django ACLStandardRule model & associates it to a view.
179+ Defines the serializer for the django ACLStandardRule model and associates it with a view.
181180 """
182181
183182 url = serializers .HyperlinkedIdentityField (
184183 view_name = "plugins-api:netbox_acls-api:aclstandardrule-detail" ,
185184 )
186- access_list = NestedAccessListSerializer ( )
185+ access_list = AccessListSerializer ( nested = True , required = True )
187186 source_prefix = PrefixSerializer (
187+ nested = True ,
188188 required = False ,
189189 allow_null = True ,
190190 default = None ,
191- nested = True
192191 )
193192
194193 class Meta :
@@ -242,24 +241,24 @@ def validate(self, data):
242241
243242class ACLExtendedRuleSerializer (NetBoxModelSerializer ):
244243 """
245- Defines the serializer for the django ACLExtendedRule model & associates it to a view.
244+ Defines the serializer for the django ACLExtendedRule model and associates it with a view.
246245 """
247246
248247 url = serializers .HyperlinkedIdentityField (
249248 view_name = "plugins-api:netbox_acls-api:aclextendedrule-detail" ,
250249 )
251- access_list = NestedAccessListSerializer ( )
250+ access_list = AccessListSerializer ( nested = True , required = True )
252251 source_prefix = PrefixSerializer (
252+ nested = True ,
253253 required = False ,
254254 allow_null = True ,
255255 default = None ,
256- nested = True
257256 )
258257 destination_prefix = PrefixSerializer (
258+ nested = True ,
259259 required = False ,
260260 allow_null = True ,
261261 default = None ,
262- nested = True
263262 )
264263
265264 class Meta :
@@ -288,6 +287,7 @@ class Meta:
288287 "remark" ,
289288 )
290289 brief_fields = ("id" , "url" , "display" )
290+
291291 def validate (self , data ):
292292 """
293293 Validate the ACLExtendedRule django model's inputs before allowing it to update the instance:
0 commit comments