@@ -325,7 +325,7 @@ def clean(self):
325
325
"""
326
326
Validates form inputs before submitting:
327
327
- Check if both interface and vminterface are set.
328
- - Check if neither interface or vminterface are set.
328
+ - Check if neither interface nor vminterface are set.
329
329
- Check that an interface's parent device/virtual_machine is assigned to the Access List.
330
330
- Check that an interface's parent device/virtual_machine is assigned to the Access List.
331
331
- Check for duplicate entry. (Because of GFK)
@@ -337,7 +337,6 @@ def clean(self):
337
337
direction = cleaned_data .get ("direction" )
338
338
interface = cleaned_data .get ("interface" )
339
339
vminterface = cleaned_data .get ("vminterface" )
340
- assigned_object = cleaned_data .get ("assigned_object" )
341
340
342
341
# Check if both interface and vminterface are set.
343
342
if interface and vminterface :
@@ -373,40 +372,42 @@ def clean(self):
373
372
).pk
374
373
access_list_host = AccessList .objects .get (pk = access_list .pk ).assigned_object
375
374
376
- # Check that an interface's parent device/virtual_machine is assigned to the Access List.
377
- if access_list_host != host :
378
- error_acl_not_assigned_to_host = "Access List not present on selected host."
379
- error_message |= {
380
- "access_list" : [error_acl_not_assigned_to_host ],
381
- assigned_object_type : [error_acl_not_assigned_to_host ],
382
- host_type : [error_acl_not_assigned_to_host ],
383
- }
384
- # Check for duplicate entry.
385
- if ACLInterfaceAssignment .objects .filter (
386
- access_list = access_list ,
387
- assigned_object_id = assigned_object_id ,
388
- assigned_object_type = assigned_object_type_id ,
389
- direction = direction ,
390
- ).exists ():
391
- error_duplicate_entry = "An ACL with this name is already associated to this interface & direction."
392
- error_message |= {
393
- "access_list" : [error_duplicate_entry ],
394
- "direction" : [error_duplicate_entry ],
395
- assigned_object_type : [error_duplicate_entry ],
396
- }
397
- # Check that the interface does not have an existing ACL applied in the direction already.
398
- if ACLInterfaceAssignment .objects .filter (
399
- assigned_object_id = assigned_object_id ,
400
- assigned_object_type = assigned_object_type_id ,
401
- direction = direction ,
402
- ).exists ():
403
- error_interface_already_assigned = (
404
- "Interfaces can only have 1 Access List assigned in each direction."
405
- )
406
- error_message |= {
407
- "direction" : [error_interface_already_assigned ],
408
- assigned_object_type : [error_interface_already_assigned ],
409
- }
375
+ # Check that an interface's parent device/virtual_machine is assigned to the Access List.
376
+ if access_list_host != host :
377
+ error_acl_not_assigned_to_host = (
378
+ "Access List not present on selected host."
379
+ )
380
+ error_message |= {
381
+ "access_list" : [error_acl_not_assigned_to_host ],
382
+ assigned_object_type : [error_acl_not_assigned_to_host ],
383
+ host_type : [error_acl_not_assigned_to_host ],
384
+ }
385
+ # Check for duplicate entry.
386
+ if ACLInterfaceAssignment .objects .filter (
387
+ access_list = access_list ,
388
+ assigned_object_id = assigned_object_id ,
389
+ assigned_object_type = assigned_object_type_id ,
390
+ direction = direction ,
391
+ ).exists ():
392
+ error_duplicate_entry = "An ACL with this name is already associated to this interface & direction."
393
+ error_message |= {
394
+ "access_list" : [error_duplicate_entry ],
395
+ "direction" : [error_duplicate_entry ],
396
+ assigned_object_type : [error_duplicate_entry ],
397
+ }
398
+ # Check that the interface does not have an existing ACL applied in the direction already.
399
+ if ACLInterfaceAssignment .objects .filter (
400
+ assigned_object_id = assigned_object_id ,
401
+ assigned_object_type = assigned_object_type_id ,
402
+ direction = direction ,
403
+ ).exists ():
404
+ error_interface_already_assigned = (
405
+ "Interfaces can only have 1 Access List assigned in each direction."
406
+ )
407
+ error_message |= {
408
+ "direction" : [error_interface_already_assigned ],
409
+ assigned_object_type : [error_interface_already_assigned ],
410
+ }
410
411
411
412
if error_message :
412
413
raise forms .ValidationError (error_message )
0 commit comments