From 16eda64272e60aaf11c6fa9e7305870e3381d5be Mon Sep 17 00:00:00 2001 From: Peter Eckel Date: Thu, 19 Oct 2023 19:29:03 +0200 Subject: [PATCH] Pylint improvements applied --- netbox_dns/__init__.py | 3 ++- netbox_dns/fields/address.py | 1 - netbox_dns/filters/nameserver.py | 1 - netbox_dns/filters/view.py | 1 - netbox_dns/forms/zone.py | 2 +- .../migrations/0001_squashed_netbox_dns_0_15.py | 6 +++--- netbox_dns/migrations/0021_record_ip_address.py | 11 +++++------ netbox_dns/migrations/0022_search.py | 2 -- netbox_dns/models.py | 15 +++++---------- netbox_dns/template_content.py | 4 +--- netbox_dns/tests/record/test_validation.py | 1 - netbox_dns/tests/zone/test_auto_ns.py | 1 - netbox_dns/tests/zone/test_views.py | 3 --- netbox_dns/views/nameserver.py | 3 +-- netbox_dns/views/view.py | 4 ++-- netbox_dns/views/zone.py | 2 -- 16 files changed, 20 insertions(+), 40 deletions(-) diff --git a/netbox_dns/__init__.py b/netbox_dns/__init__.py index ff1c9c27..214bc246 100644 --- a/netbox_dns/__init__.py +++ b/netbox_dns/__init__.py @@ -1,6 +1,7 @@ -from extras.plugins import PluginConfig import logging +from extras.plugins import PluginConfig + logger = logging.getLogger("netbox.config") __version__ = "0.20.1" diff --git a/netbox_dns/fields/address.py b/netbox_dns/fields/address.py index 2fb2fa78..db022d44 100644 --- a/netbox_dns/fields/address.py +++ b/netbox_dns/fields/address.py @@ -1,6 +1,5 @@ from django import forms from django.db import models -from django.db.models import Lookup from django.core.exceptions import ValidationError from netaddr import AddrFormatError, IPAddress diff --git a/netbox_dns/filters/nameserver.py b/netbox_dns/filters/nameserver.py index 6b11fe3e..291830eb 100755 --- a/netbox_dns/filters/nameserver.py +++ b/netbox_dns/filters/nameserver.py @@ -1,4 +1,3 @@ -import django_filters from django.db.models import Q from netbox.filtersets import NetBoxModelFilterSet diff --git a/netbox_dns/filters/view.py b/netbox_dns/filters/view.py index d95af4ec..fad088c2 100644 --- a/netbox_dns/filters/view.py +++ b/netbox_dns/filters/view.py @@ -1,4 +1,3 @@ -import django_filters from django.db.models import Q from netbox.filtersets import NetBoxModelFilterSet diff --git a/netbox_dns/forms/zone.py b/netbox_dns/forms/zone.py index 32364d62..0073ecfc 100755 --- a/netbox_dns/forms/zone.py +++ b/netbox_dns/forms/zone.py @@ -320,7 +320,7 @@ def clean_soa_ttl(self): def clean_soa_mname(self): soa_mname = self._clean_field_with_defaults("soa_mname") - if type(soa_mname) == str: + if isinstance(soa_mname, str): try: soa_mname = NameServer.objects.get(name=soa_mname) except NameServer.DoesNotExist: diff --git a/netbox_dns/migrations/0001_squashed_netbox_dns_0_15.py b/netbox_dns/migrations/0001_squashed_netbox_dns_0_15.py index 4fb0cadd..68936c50 100644 --- a/netbox_dns/migrations/0001_squashed_netbox_dns_0_15.py +++ b/netbox_dns/migrations/0001_squashed_netbox_dns_0_15.py @@ -1,11 +1,11 @@ -# Generated by Django 4.1.2 on 2022-11-30 15:35 +import taggit.managers import django.core.serializers.json import django.core.validators -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models + import netbox_dns.fields.network -import taggit.managers class Migration(migrations.Migration): diff --git a/netbox_dns/migrations/0021_record_ip_address.py b/netbox_dns/migrations/0021_record_ip_address.py index 3d84b4fc..6909d162 100644 --- a/netbox_dns/migrations/0021_record_ip_address.py +++ b/netbox_dns/migrations/0021_record_ip_address.py @@ -1,11 +1,10 @@ -# Generated by Django 4.1.4 on 2022-12-15 10:01 +import taggit.managers import django.core.validators -from django.db import migrations, models import django.db.models.deletion -import netbox_dns.fields.address -import taggit.managers +from django.db import migrations, models +import netbox_dns.fields.address from netbox_dns.models import RecordTypeChoices from netbox_dns.utilities import arpa_to_prefix @@ -13,8 +12,8 @@ def fqdn(record): if record.name == "@": return f"{record.zone.name}." - else: - return f"{record.name}.{record.zone.name}." + + return f"{record.name}.{record.zone.name}." def address_from_name(record): diff --git a/netbox_dns/migrations/0022_search.py b/netbox_dns/migrations/0022_search.py index b67baaf4..f904f3cd 100644 --- a/netbox_dns/migrations/0022_search.py +++ b/netbox_dns/migrations/0022_search.py @@ -1,5 +1,3 @@ -import sys - from django.db import migrations diff --git a/netbox_dns/models.py b/netbox_dns/models.py index ccb05f59..0552fd2f 100644 --- a/netbox_dns/models.py +++ b/netbox_dns/models.py @@ -9,27 +9,24 @@ from dns.rdtypes.ANY import SOA from dns.exception import DNSException -from ipam.models import IPAddress - from django.core.validators import ( MinValueValidator, MaxValueValidator, ) - from django.core.exceptions import ObjectDoesNotExist, ValidationError from django.db import models, transaction from django.db.models import Q, Max, ExpressionWrapper, BooleanField from django.db.models.functions import Length from django.urls import reverse - from django.db.models.signals import m2m_changed from django.dispatch import receiver -from utilities.querysets import RestrictedQuerySet -from utilities.choices import ChoiceSet - from netbox.models import NetBoxModel from netbox.search import SearchIndex, register_search +from utilities.querysets import RestrictedQuerySet +from utilities.choices import ChoiceSet +from extras.plugins.utils import get_plugin_config +from ipam.models import IPAddress from netbox_dns.fields import NetworkField, AddressField from netbox_dns.utilities import ( @@ -44,8 +41,6 @@ validate_extended_hostname, ) -from extras.plugins.utils import get_plugin_config - class NameServer(NetBoxModel): name = models.CharField( @@ -500,7 +495,7 @@ def clean(self, *args, **kwargs): ) from None try: - soa_rname = dns_name.from_text(self.soa_rname, origin=dns_name.root) + dns_name.from_text(self.soa_rname, origin=dns_name.root) validate_fqdn(self.soa_rname) except (DNSException, ValidationError) as exc: raise ValidationError( diff --git a/netbox_dns/template_content.py b/netbox_dns/template_content.py index bbdb6494..475db8b3 100644 --- a/netbox_dns/template_content.py +++ b/netbox_dns/template_content.py @@ -1,9 +1,7 @@ -from django.db.models.functions import Length - from extras.plugins.utils import get_plugin_config from extras.plugins import PluginTemplateExtension -from netbox_dns.models import Record, RecordTypeChoices, Zone, View, NameServer +from netbox_dns.models import Record, Zone, View, NameServer from netbox_dns.tables import RelatedRecordTable diff --git a/netbox_dns/tests/record/test_validation.py b/netbox_dns/tests/record/test_validation.py index 5ac4a97b..1b5b4b63 100644 --- a/netbox_dns/tests/record/test_validation.py +++ b/netbox_dns/tests/record/test_validation.py @@ -261,7 +261,6 @@ def test_cname_and_nsec(self): name1 = "test1" name2 = "test2" - address = "fe80:dead:beef:1::42" f_record1 = Record( zone=f_zone, diff --git a/netbox_dns/tests/zone/test_auto_ns.py b/netbox_dns/tests/zone/test_auto_ns.py index 9078dcd4..9ed3becd 100644 --- a/netbox_dns/tests/zone/test_auto_ns.py +++ b/netbox_dns/tests/zone/test_auto_ns.py @@ -229,7 +229,6 @@ def test_delete_ns_ns_record_removed(self): ) def test_delete_soa_ns_exception(self): - zone = self.zone nameserver = self.nameservers[0] with self.assertRaisesRegexp( diff --git a/netbox_dns/tests/zone/test_views.py b/netbox_dns/tests/zone/test_views.py index 865d6faf..1d3d9dd5 100644 --- a/netbox_dns/tests/zone/test_views.py +++ b/netbox_dns/tests/zone/test_views.py @@ -1,5 +1,4 @@ from utilities.testing import ViewTestCases -from utilities.testing import create_tags from netbox_dns.tests.custom import ModelViewTestCase from netbox_dns.models import NameServer, View, Zone, ZoneStatusChoices @@ -52,8 +51,6 @@ def setUpTestData(cls): ) Zone.objects.bulk_create(cls.zones) - tags = create_tags("Alpha", "Bravo", "Charlie") - cls.bulk_edit_data = { "status": ZoneStatusChoices.STATUS_PARKED, } diff --git a/netbox_dns/views/nameserver.py b/netbox_dns/views/nameserver.py index 382618b4..4aa2d6c8 100644 --- a/netbox_dns/views/nameserver.py +++ b/netbox_dns/views/nameserver.py @@ -1,6 +1,7 @@ from dns import name as dns_name from netbox.views import generic +from utilities.views import ViewTab, register_model_view from netbox_dns.filters import NameServerFilter, ZoneFilter from netbox_dns.forms import ( @@ -12,8 +13,6 @@ from netbox_dns.models import Zone, NameServer from netbox_dns.tables import NameServerTable, ZoneTable -from utilities.views import ViewTab, register_model_view - class NameServerListView(generic.ObjectListView): queryset = NameServer.objects.all() diff --git a/netbox_dns/views/view.py b/netbox_dns/views/view.py index 121d4797..b611d852 100644 --- a/netbox_dns/views/view.py +++ b/netbox_dns/views/view.py @@ -1,3 +1,5 @@ +from utilities.views import ViewTab, register_model_view + from netbox.views import generic from netbox_dns.models import View, Zone @@ -5,8 +7,6 @@ from netbox_dns.forms import ViewForm, ViewFilterForm, ViewImportForm, ViewBulkEditForm from netbox_dns.tables import ViewTable, ZoneTable -from utilities.views import ViewTab, register_model_view - class ViewView(generic.ObjectView): queryset = View.objects.all().prefetch_related("zone_set") diff --git a/netbox_dns/views/zone.py b/netbox_dns/views/zone.py index aab560a0..c1752e35 100644 --- a/netbox_dns/views/zone.py +++ b/netbox_dns/views/zone.py @@ -1,7 +1,5 @@ from dns import name as dns_name -from django.urls import reverse - from netbox.views import generic from utilities.views import ViewTab, register_model_view