Skip to content

Commit 10699e0

Browse files
committed
fixed unbound local variable assignments
1 parent f8aadff commit 10699e0

File tree

2 files changed

+40
-36
lines changed

2 files changed

+40
-36
lines changed

netbox_acls/forms/models.py

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ def clean(self):
325325
"""
326326
Validates form inputs before submitting:
327327
- 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.
329329
- Check that an interface's parent device/virtual_machine is assigned to the Access List.
330330
- Check that an interface's parent device/virtual_machine is assigned to the Access List.
331331
- Check for duplicate entry. (Because of GFK)
@@ -337,7 +337,6 @@ def clean(self):
337337
direction = cleaned_data.get("direction")
338338
interface = cleaned_data.get("interface")
339339
vminterface = cleaned_data.get("vminterface")
340-
assigned_object = cleaned_data.get("assigned_object")
341340

342341
# Check if both interface and vminterface are set.
343342
if interface and vminterface:
@@ -373,40 +372,42 @@ def clean(self):
373372
).pk
374373
access_list_host = AccessList.objects.get(pk=access_list.pk).assigned_object
375374

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+
}
410411

411412
if error_message:
412413
raise forms.ValidationError(error_message)

netbox_acls/template_content.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ def right_page(self):
3131
elif ctype.model == "vminterface":
3232
parent_type = "virtual_machine"
3333
parent_id = obj.virtual_machine.pk
34+
else:
35+
parent_type = None
36+
parent_id = None
3437

3538
return self.render(
3639
"inc/assigned_interface/access_lists.html",

0 commit comments

Comments
 (0)