Compare commits

...

4 Commits

Author SHA1 Message Date
Seb Harrington
974870adeb Attempt to fix the filter by role (no longer device_role) 2024-05-03 15:49:07 +01:00
Seb Harrington
69fbd6aef9 Remove filtering of devices 2024-05-03 13:55:16 +01:00
Seb Harrington
b422a926de Remove VLAN 2024-05-03 11:03:44 +01:00
Seb Harrington
242fe8e320 First pass at making VLAN optional 2024-05-03 10:20:11 +01:00
2 changed files with 9 additions and 8 deletions

View File

@ -15,6 +15,7 @@ class DeviceMapFilterForm(BootstrapMixin, forms.Form):
)
vlan = DynamicModelChoiceField(
queryset=VLAN.objects.all(),
required=False,
label="VLAN",
help_text="Filter devices by VLAN attached to any device interface",
query_params={"group_id": "$vlan_group"}

View File

@ -26,18 +26,18 @@ class MapView(PermissionRequiredMixin, View):
form = self.form(request.GET)
if form.is_valid():
interfaces = Interface.objects.all()
vlan = form.cleaned_data['vlan']
#vlan = form.cleaned_data['vlan']
interfaces = interfaces.filter(Q(untagged_vlan=vlan) | Q(tagged_vlans=vlan))
#interfaces = interfaces.filter(Q(untagged_vlan=vlan) | Q(tagged_vlans=vlan))
devices = Device.objects.filter(interfaces__in=interfaces).distinct()
if device_roles := form.cleaned_data['device_roles']:
devices = devices.filter(device_role__in=device_roles)
devices = devices.filter(role=device_roles)
geolocated_devices = {d: coords for d in devices if (coords := get_device_location(d))}
non_geolocated_devices = set(devices) - set(geolocated_devices.keys())
map_data = configure_leaflet_map("geomap", geolocated_devices, form.cleaned_data['calculate_connections'])
map_data['vlan'] = vlan.id
#map_data['vlan'] = vlan.id
return render(request, self.template_name, context=dict(
filter_form=form, map_data=map_data, non_geolocated_devices=non_geolocated_devices
))
@ -61,12 +61,12 @@ class ConnectedCpeAjaxView(PermissionRequiredMixin, View):
form = self.form(request.GET)
if form.is_valid():
data = form.cleaned_data
connected_devices_qs = get_connected_devices(device, vlan=data['vlan'])\
.filter(device_role__name=plugin_settings['cpe_device_role']).order_by()
connected_devices_qs = get_connected_devices(device, vlan=data['vlan'])
#\
# .filter(device_role__name=plugin_settings['cpe_device_role']).order_by()
connected_devices = [dict(id=d.id, name=d.name, url=d.get_absolute_url(), comments=d.comments)
for d in connected_devices_qs]
# Sorting list of CPE devices by the sequence of integers contained in the comments
connected_devices.sort(key=lambda d: tuple(int(n) for n in INTEGER_REGEXP.findall(d['comments'])))
return JsonResponse(dict(status=True, cpe_devices=connected_devices,
device_type=f'{device.device_type.manufacturer.name} {device.device_type.model}'))
else: