Skip to content

Instantly share code, notes, and snippets.

@renatoalmeidaoliveira
Last active December 20, 2022 17:37
Show Gist options
  • Save renatoalmeidaoliveira/460f465a434617d5569779ef413da7b6 to your computer and use it in GitHub Desktop.
Save renatoalmeidaoliveira/460f465a434617d5569779ef413da7b6 to your computer and use it in GitHub Desktop.
Device case sensitive report
from dcim.models import Device, DeviceType, Site
from extras.reports import Report
class DeviceReport(Report):
description = "Check device case insensitive name"
@property
def name(self):
return "Device Name Report"
def test_case_insensitive_name(self):
devices = Device.objects.all()
for device in devices:
if device.name is not None:
repeated_name = devices.filter(name__iexact=device.name, site_id=device.site.id).exclude(id=device.id)
for repeaded_device in repeated_name:
self.log_failure(
device, f"Device with repeated name (case insensitive) [{repeaded_device}]({repeaded_device.get_absolute_url()})"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment