Last active
December 20, 2022 17:37
-
-
Save renatoalmeidaoliveira/460f465a434617d5569779ef413da7b6 to your computer and use it in GitHub Desktop.
Device case sensitive report
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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