Misc pep8 cleanups

This commit is contained in:
nikolark committed 2016-06-19 18:29:07 +02:00
1 parent 257b00be1b
commit 277fde9809
7 files changed
+22 -20

No files matched your search

+14 -12
View File
@@ -3,9 +3,10 @@ import ipaddress
from django.contrib import admin, messages from django.contrib import admin, messages
from django.db.models import Count from django.db.models import Count
from mdb.forms import InterfaceForm from mdb.forms import InterfaceForm
from mdb.models import Ip6Address, Interface, Ip4Address, DhcpOption, DhcpCustomField, DomainSrvRecord, DomainTxtRecord, \ from mdb.models import (
DomainCnameRecord, DomainARecord, Domain, Host, Ip4Subnet, Ip6Subnet, Nameserver, MailExchange, OperatingSystem, \ Ip6Address, Interface, Ip4Address, DhcpOption, DhcpCustomField, DomainSrvRecord, DomainTxtRecord,
HostType, DhcpConfig, DomainAAAARecord DomainCnameRecord, DomainARecord, Domain, Host, Ip4Subnet, Ip6Subnet, Nameserver, MailExchange, OperatingSystem,
HostType, DhcpConfig, DomainAAAARecord)
class Ip6AddressInline(admin.TabularInline): class Ip6AddressInline(admin.TabularInline):
@@ -37,22 +38,22 @@ class HostAdmin(admin.ModelAdmin):
'fields': ('owner', 'location', 'description') 'fields': ('owner', 'location', 'description')
}), }),
('Hardware and Software Information', { ('Hardware and Software Information', {
'fields': (('hostname', 'host_type'), ('pxe_key', 'pxe_installable'), ('brand', 'model'), 'serial_number', ('operating_system', 'virtual')) 'fields': (
('hostname', 'host_type'),
('pxe_key', 'pxe_installable'),
('brand', 'model'),
'serial_number',
('operating_system', 'virtual'))
}), }),
# FIXME: Not in use
# ('Domain and Kerberos Information', {
# 'description': 'If this host is a member of the LDAP domain, you need to tick the request kerberos principal checkbox. A principal will then be created for the host.',
# 'classes': ['collapse'],
# 'fields': ('request_kerberos_principal', 'kerberos_principal_created',
# ('kerberos_principal_name', 'kerberos_principal_created_date'))
# }),
) )
actions = ['set_installable'] actions = ['set_installable']
@staticmethod
def mac_addresses(self, host): def mac_addresses(self, host):
addresses = host.interface_set.filter(macaddr__isnull=False).values_list('macaddr', flat=True) addresses = host.interface_set.filter(macaddr__isnull=False).values_list('macaddr', flat=True)
return ", ".join(addresses) return ", ".join(addresses)
@staticmethod
def ip_addresses(self, host): def ip_addresses(self, host):
addresses = host.interface_set.filter(ip4address__isnull=False).values_list('ip4address__address', flat=True) addresses = host.interface_set.filter(ip4address__isnull=False).values_list('ip4address__address', flat=True)
return ", ".join(addresses) return ", ".join(addresses)
@@ -69,7 +70,8 @@ class HostAdmin(admin.ModelAdmin):
ipv6_enabled.boolean = True ipv6_enabled.boolean = True
def _get_host_warning_message(self, host, ifs): @staticmethod
def _get_host_warning_message(host, ifs):
ifs_str = ', '.join([_if.name for _if in ifs]) ifs_str = ', '.join([_if.name for _if in ifs])
return 'Host {} might not be installable since interface(s) {} has no IP set.'.format(host, ifs_str) return 'Host {} might not be installable since interface(s) {} has no IP set.'.format(host, ifs_str)
+1 -1
View File
@@ -15,6 +15,6 @@ class HostPXEValidate(APIView):
serializer.is_valid(raise_exception=True) serializer.is_valid(raise_exception=True)
host = serializer.save() # sets Host.pxe_installable=False serializer.save() # sets Host.pxe_installable=False
return Response({'valid_pxe_key': True}) return Response({'valid_pxe_key': True})
+1 -1
View File
@@ -7,4 +7,4 @@ class MdbAppConfig(AppConfig):
def ready(self): def ready(self):
# all models are loaded, now attach signals # all models are loaded, now attach signals
import mdb.signals import mdb.signals # noqa
+1 -1
View File
@@ -319,7 +319,7 @@ class Ip6Subnet(models.Model):
# content += "$ORIGIN " + ".".join(network.exploded.replace(":","")[:16])[::-1] + ".ip6.arpa.\n" # content += "$ORIGIN " + ".".join(network.exploded.replace(":","")[:16])[::-1] + ".ip6.arpa.\n"
for addr in self.ip6address_set.all(): for addr in self.ip6address_set.all():
#if addr.interface_set.count() == 0: continue # if addr.interface_set.count() == 0: continue
if addr.interface.domain is None: if addr.interface.domain is None:
continue continue
+2 -2
View File
@@ -68,13 +68,13 @@ class RunManagementCommands(TestCase):
fixtures = ['test_data'] fixtures = ['test_data']
def test_zone_sync(self): def test_zone_sync(self):
expected_zone_file = '' # expected_zone_file = ''
with io.BytesIO() as f: with io.BytesIO() as f:
call_command('zone-sync', debug=True, stdout=f) call_command('zone-sync', debug=True, stdout=f)
# TODO check expected_zone_file # TODO check expected_zone_file
def test_dhcp_sync(self): def test_dhcp_sync(self):
expected_dhcp_file = '' # expected_dhcp_file = ''
with io.BytesIO() as f: with io.BytesIO() as f:
call_command('dhcp-sync', stdout=f) call_command('dhcp-sync', stdout=f)
# TODO check expected_dhcp_file # TODO check expected_dhcp_file
+2 -2
View File
@@ -17,7 +17,7 @@ def format_domain_serial_and_add_one(serial):
""" The serial contains todays date, just update it. """ """ The serial contains todays date, just update it. """
try: try:
number = int(res[0]) number = int(res[0])
except: except ValueError:
number = 1 number = 1
if number >= 99: if number >= 99:
""" This is bad... Just keep the number on 99. """ This is bad... Just keep the number on 99.
@@ -31,4 +31,4 @@ def format_domain_serial_and_add_one(serial):
else: else:
""" Just return the first serial for today. """ """ Just return the first serial for today. """
return "%4d%02d%02d%02d" % \ return "%4d%02d%02d%02d" % \
(today.year, today.month, today.day, 1) (today.year, today.month, today.day, 1)
+1 -1
View File
@@ -116,7 +116,7 @@ SUIT_CONFIG = {
), ),
# misc # misc
'LIST_PER_PAGE': 30 'LIST_PER_PAGE': 35
} }
REST_FRAMEWORK = { REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAuthenticated',), 'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAuthenticated',),