diff --git a/.gitignore b/.gitignore index 4fc377333..a86cd73ae 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *.pyc /netbox/netbox/configuration.py +/netbox/netbox/ldap_config.py /netbox/static .idea /*.sh diff --git a/.travis.yml b/.travis.yml index e8822e5e3..b23c9d8fc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,9 @@ env: language: python python: - "2.7" + - "3.4" + - "3.5" + - "3.6" install: - pip install -r requirements.txt - pip install pep8 diff --git a/netbox/circuits/models.py b/netbox/circuits/models.py index 7f6cc4f21..9972e564f 100644 --- a/netbox/circuits/models.py +++ b/netbox/circuits/models.py @@ -51,7 +51,7 @@ class Provider(CreatedUpdatedModel, CustomFieldModel): class Meta: ordering = ['name'] - def __unicode__(self): + def __str__(self): return self.name def get_absolute_url(self): @@ -78,7 +78,7 @@ class CircuitType(models.Model): class Meta: ordering = ['name'] - def __unicode__(self): + def __str__(self): return self.name def get_absolute_url(self): @@ -105,7 +105,7 @@ class Circuit(CreatedUpdatedModel, CustomFieldModel): ordering = ['provider', 'cid'] unique_together = ['provider', 'cid'] - def __unicode__(self): + def __str__(self): return u'{} {}'.format(self.provider, self.cid) def get_absolute_url(self): @@ -156,7 +156,7 @@ class CircuitTermination(models.Model): ordering = ['circuit', 'term_side'] unique_together = ['circuit', 'term_side'] - def __unicode__(self): + def __str__(self): return u'{} (Side {})'.format(self.circuit, self.get_term_side_display()) def get_peer_termination(self): diff --git a/netbox/dcim/forms.py b/netbox/dcim/forms.py index cb35ff881..9931ffd8b 100644 --- a/netbox/dcim/forms.py +++ b/netbox/dcim/forms.py @@ -13,7 +13,7 @@ from utilities.forms import ( SlugField, ) -from formfields import MACAddressFormField +from .formfields import MACAddressFormField from .models import ( DeviceBay, DeviceBayTemplate, CONNECTION_STATUS_CHOICES, CONNECTION_STATUS_PLANNED, CONNECTION_STATUS_CONNECTED, ConsolePort, ConsolePortTemplate, ConsoleServerPort, ConsoleServerPortTemplate, Device, DeviceRole, DeviceType, diff --git a/netbox/dcim/models.py b/netbox/dcim/models.py index 6274f3a53..b2d6543eb 100644 --- a/netbox/dcim/models.py +++ b/netbox/dcim/models.py @@ -222,7 +222,7 @@ class Site(CreatedUpdatedModel, CustomFieldModel): class Meta: ordering = ['name'] - def __unicode__(self): + def __str__(self): return self.name def get_absolute_url(self): @@ -282,7 +282,7 @@ class RackGroup(models.Model): ['site', 'slug'], ] - def __unicode__(self): + def __str__(self): return u'{} - {}'.format(self.site.name, self.name) def get_absolute_url(self): @@ -300,7 +300,7 @@ class RackRole(models.Model): class Meta: ordering = ['name'] - def __unicode__(self): + def __str__(self): return self.name def get_absolute_url(self): @@ -343,7 +343,7 @@ class Rack(CreatedUpdatedModel, CustomFieldModel): ['site', 'facility_id'], ] - def __unicode__(self): + def __str__(self): return self.display_name def get_absolute_url(self): @@ -487,7 +487,7 @@ class Manufacturer(models.Model): class Meta: ordering = ['name'] - def __unicode__(self): + def __str__(self): return self.name def get_absolute_url(self): @@ -538,7 +538,7 @@ class DeviceType(models.Model, CustomFieldModel): ['manufacturer', 'slug'], ] - def __unicode__(self): + def __str__(self): return self.model def __init__(self, *args, **kwargs): @@ -619,7 +619,7 @@ class ConsolePortTemplate(models.Model): ordering = ['device_type', 'name'] unique_together = ['device_type', 'name'] - def __unicode__(self): + def __str__(self): return self.name @@ -634,7 +634,7 @@ class ConsoleServerPortTemplate(models.Model): ordering = ['device_type', 'name'] unique_together = ['device_type', 'name'] - def __unicode__(self): + def __str__(self): return self.name @@ -649,7 +649,7 @@ class PowerPortTemplate(models.Model): ordering = ['device_type', 'name'] unique_together = ['device_type', 'name'] - def __unicode__(self): + def __str__(self): return self.name @@ -664,7 +664,7 @@ class PowerOutletTemplate(models.Model): ordering = ['device_type', 'name'] unique_together = ['device_type', 'name'] - def __unicode__(self): + def __str__(self): return self.name @@ -721,7 +721,7 @@ class InterfaceTemplate(models.Model): ordering = ['device_type', 'name'] unique_together = ['device_type', 'name'] - def __unicode__(self): + def __str__(self): return self.name @@ -736,7 +736,7 @@ class DeviceBayTemplate(models.Model): ordering = ['device_type', 'name'] unique_together = ['device_type', 'name'] - def __unicode__(self): + def __str__(self): return self.name @@ -756,7 +756,7 @@ class DeviceRole(models.Model): class Meta: ordering = ['name'] - def __unicode__(self): + def __str__(self): return self.name def get_absolute_url(self): @@ -776,7 +776,7 @@ class Platform(models.Model): class Meta: ordering = ['name'] - def __unicode__(self): + def __str__(self): return self.name def get_absolute_url(self): @@ -828,7 +828,7 @@ class Device(CreatedUpdatedModel, CustomFieldModel): ordering = ['name'] unique_together = ['rack', 'position', 'face'] - def __unicode__(self): + def __str__(self): return self.display_name def get_absolute_url(self): @@ -982,7 +982,7 @@ class ConsolePort(models.Model): ordering = ['device', 'name'] unique_together = ['device', 'name'] - def __unicode__(self): + def __str__(self): return self.name # Used for connections export @@ -1023,7 +1023,7 @@ class ConsoleServerPort(models.Model): class Meta: unique_together = ['device', 'name'] - def __unicode__(self): + def __str__(self): return self.name @@ -1041,7 +1041,7 @@ class PowerPort(models.Model): ordering = ['device', 'name'] unique_together = ['device', 'name'] - def __unicode__(self): + def __str__(self): return self.name # Used for connections export @@ -1076,7 +1076,7 @@ class PowerOutlet(models.Model): class Meta: unique_together = ['device', 'name'] - def __unicode__(self): + def __str__(self): return self.name @@ -1099,7 +1099,7 @@ class Interface(models.Model): ordering = ['device', 'name'] unique_together = ['device', 'name'] - def __unicode__(self): + def __str__(self): return self.name def clean(self): @@ -1189,7 +1189,7 @@ class DeviceBay(models.Model): ordering = ['device', 'name'] unique_together = ['device', 'name'] - def __unicode__(self): + def __str__(self): return u'{} - {}'.format(self.device.name, self.name) def clean(self): @@ -1223,5 +1223,5 @@ class Module(models.Model): ordering = ['device__id', 'parent__id', 'name'] unique_together = ['device', 'parent', 'name'] - def __unicode__(self): + def __str__(self): return self.name diff --git a/netbox/extras/models.py b/netbox/extras/models.py index d45e4846f..31f959dd0 100644 --- a/netbox/extras/models.py +++ b/netbox/extras/models.py @@ -114,7 +114,7 @@ class CustomField(models.Model): class Meta: ordering = ['weight', 'name'] - def __unicode__(self): + def __str__(self): return self.label or self.name.replace('_', ' ').capitalize() def serialize_value(self, value): @@ -164,7 +164,7 @@ class CustomFieldValue(models.Model): ordering = ['obj_type', 'obj_id'] unique_together = ['field', 'obj_type', 'obj_id'] - def __unicode__(self): + def __str__(self): return u'{} {}'.format(self.obj, self.field) @property @@ -193,7 +193,7 @@ class CustomFieldChoice(models.Model): ordering = ['field', 'weight', 'value'] unique_together = ['field', 'value'] - def __unicode__(self): + def __str__(self): return self.value def clean(self): @@ -217,7 +217,7 @@ class Graph(models.Model): class Meta: ordering = ['type', 'weight', 'name'] - def __unicode__(self): + def __str__(self): return self.name def embed_url(self, obj): @@ -245,7 +245,7 @@ class ExportTemplate(models.Model): ['content_type', 'name'] ] - def __unicode__(self): + def __str__(self): return u'{}: {}'.format(self.content_type, self.name) def to_response(self, context_dict, filename): @@ -278,7 +278,7 @@ class TopologyMap(models.Model): class Meta: ordering = ['name'] - def __unicode__(self): + def __str__(self): return self.name @property @@ -344,7 +344,7 @@ class UserAction(models.Model): class Meta: ordering = ['-time'] - def __unicode__(self): + def __str__(self): if self.message: return u'{} {}'.format(self.user, self.message) return u'{} {} {}'.format(self.user, self.get_action_display(), self.content_type) diff --git a/netbox/generate_secret_key.py b/netbox/generate_secret_key.py index d935910f6..6855ee840 100755 --- a/netbox/generate_secret_key.py +++ b/netbox/generate_secret_key.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 # This script will generate a random 50-character string suitable for use as a SECRET_KEY. import os import random diff --git a/netbox/ipam/models.py b/netbox/ipam/models.py index c8afc6402..c0ca2b0ad 100644 --- a/netbox/ipam/models.py +++ b/netbox/ipam/models.py @@ -89,7 +89,7 @@ class VRF(CreatedUpdatedModel, CustomFieldModel): verbose_name = 'VRF' verbose_name_plural = 'VRFs' - def __unicode__(self): + def __str__(self): return self.name def get_absolute_url(self): @@ -120,7 +120,7 @@ class RIR(models.Model): verbose_name = 'RIR' verbose_name_plural = 'RIRs' - def __unicode__(self): + def __str__(self): return self.name def get_absolute_url(self): @@ -142,7 +142,7 @@ class Aggregate(CreatedUpdatedModel, CustomFieldModel): class Meta: ordering = ['family', 'prefix'] - def __unicode__(self): + def __str__(self): return str(self.prefix) def get_absolute_url(self): @@ -216,7 +216,7 @@ class Role(models.Model): class Meta: ordering = ['weight', 'name'] - def __unicode__(self): + def __str__(self): return self.name @property @@ -292,7 +292,7 @@ class Prefix(CreatedUpdatedModel, CustomFieldModel): ordering = ['vrf', 'family', 'prefix'] verbose_name_plural = 'prefixes' - def __unicode__(self): + def __str__(self): return str(self.prefix) def get_absolute_url(self): @@ -409,7 +409,7 @@ class IPAddress(CreatedUpdatedModel, CustomFieldModel): verbose_name = 'IP address' verbose_name_plural = 'IP addresses' - def __unicode__(self): + def __str__(self): return str(self.address) def get_absolute_url(self): @@ -486,7 +486,7 @@ class VLANGroup(models.Model): verbose_name = 'VLAN group' verbose_name_plural = 'VLAN groups' - def __unicode__(self): + def __str__(self): return u'{} - {}'.format(self.site.name, self.name) def get_absolute_url(self): @@ -524,7 +524,7 @@ class VLAN(CreatedUpdatedModel, CustomFieldModel): verbose_name = 'VLAN' verbose_name_plural = 'VLANs' - def __unicode__(self): + def __str__(self): return self.display_name def get_absolute_url(self): @@ -576,5 +576,5 @@ class Service(CreatedUpdatedModel): ordering = ['device', 'protocol', 'port'] unique_together = ['device', 'protocol', 'port'] - def __unicode__(self): + def __str__(self): return u'{} ({}/{})'.format(self.name, self.port, self.get_protocol_display()) diff --git a/netbox/manage.py b/netbox/manage.py index 2ce3867f3..737592ae8 100755 --- a/netbox/manage.py +++ b/netbox/manage.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import os import sys diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index e379372d5..dcf687497 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -6,7 +6,7 @@ from django.contrib.messages import constants as messages from django.core.exceptions import ImproperlyConfigured try: - import configuration + import netbox.configuration except ImportError: raise ImproperlyConfigured("Configuration file is not present. Please define netbox/netbox/configuration.py per " "the documentation.") @@ -17,40 +17,40 @@ VERSION = '1.8.3-dev' # Import local configuration for setting in ['ALLOWED_HOSTS', 'DATABASE', 'SECRET_KEY']: try: - globals()[setting] = getattr(configuration, setting) + globals()[setting] = getattr(netbox.configuration, setting) except AttributeError: raise ImproperlyConfigured("Mandatory setting {} is missing from configuration.py. Please define it per the " "documentation.".format(setting)) # Default configurations -ADMINS = getattr(configuration, 'ADMINS', []) -DEBUG = getattr(configuration, 'DEBUG', False) -EMAIL = getattr(configuration, 'EMAIL', {}) -LOGIN_REQUIRED = getattr(configuration, 'LOGIN_REQUIRED', False) -BASE_PATH = getattr(configuration, 'BASE_PATH', '') +ADMINS = getattr(netbox.configuration, 'ADMINS', []) +DEBUG = getattr(netbox.configuration, 'DEBUG', False) +EMAIL = getattr(netbox.configuration, 'EMAIL', {}) +LOGIN_REQUIRED = getattr(netbox.configuration, 'LOGIN_REQUIRED', False) +BASE_PATH = getattr(netbox.configuration, 'BASE_PATH', '') if BASE_PATH: BASE_PATH = BASE_PATH.strip('/') + '/' # Enforce trailing slash only -MAINTENANCE_MODE = getattr(configuration, 'MAINTENANCE_MODE', False) -PAGINATE_COUNT = getattr(configuration, 'PAGINATE_COUNT', 50) -NETBOX_USERNAME = getattr(configuration, 'NETBOX_USERNAME', '') -NETBOX_PASSWORD = getattr(configuration, 'NETBOX_PASSWORD', '') -TIME_ZONE = getattr(configuration, 'TIME_ZONE', 'UTC') -DATE_FORMAT = getattr(configuration, 'DATE_FORMAT', 'N j, Y') -SHORT_DATE_FORMAT = getattr(configuration, 'SHORT_DATE_FORMAT', 'Y-m-d') -TIME_FORMAT = getattr(configuration, 'TIME_FORMAT', 'g:i a') -SHORT_TIME_FORMAT = getattr(configuration, 'SHORT_TIME_FORMAT', 'H:i:s') -DATETIME_FORMAT = getattr(configuration, 'DATETIME_FORMAT', 'N j, Y g:i a') -SHORT_DATETIME_FORMAT = getattr(configuration, 'SHORT_DATETIME_FORMAT', 'Y-m-d H:i') -BANNER_TOP = getattr(configuration, 'BANNER_TOP', False) -BANNER_BOTTOM = getattr(configuration, 'BANNER_BOTTOM', False) -PREFER_IPV4 = getattr(configuration, 'PREFER_IPV4', False) -ENFORCE_GLOBAL_UNIQUE = getattr(configuration, 'ENFORCE_GLOBAL_UNIQUE', False) +MAINTENANCE_MODE = getattr(netbox.configuration, 'MAINTENANCE_MODE', False) +PAGINATE_COUNT = getattr(netbox.configuration, 'PAGINATE_COUNT', 50) +NETBOX_USERNAME = getattr(netbox.configuration, 'NETBOX_USERNAME', '') +NETBOX_PASSWORD = getattr(netbox.configuration, 'NETBOX_PASSWORD', '') +TIME_ZONE = getattr(netbox.configuration, 'TIME_ZONE', 'UTC') +DATE_FORMAT = getattr(netbox.configuration, 'DATE_FORMAT', 'N j, Y') +SHORT_DATE_FORMAT = getattr(netbox.configuration, 'SHORT_DATE_FORMAT', 'Y-m-d') +TIME_FORMAT = getattr(netbox.configuration, 'TIME_FORMAT', 'g:i a') +SHORT_TIME_FORMAT = getattr(netbox.configuration, 'SHORT_TIME_FORMAT', 'H:i:s') +DATETIME_FORMAT = getattr(netbox.configuration, 'DATETIME_FORMAT', 'N j, Y g:i a') +SHORT_DATETIME_FORMAT = getattr(netbox.configuration, 'SHORT_DATETIME_FORMAT', 'Y-m-d H:i') +BANNER_TOP = getattr(netbox.configuration, 'BANNER_TOP', False) +BANNER_BOTTOM = getattr(netbox.configuration, 'BANNER_BOTTOM', False) +PREFER_IPV4 = getattr(netbox.configuration, 'PREFER_IPV4', False) +ENFORCE_GLOBAL_UNIQUE = getattr(netbox.configuration, 'ENFORCE_GLOBAL_UNIQUE', False) CSRF_TRUSTED_ORIGINS = ALLOWED_HOSTS # Attempt to import LDAP configuration if it has been defined LDAP_IGNORE_CERT_ERRORS = False try: - from ldap_config import * + from netbox.ldap_config import * LDAP_CONFIGURED = True except ImportError: LDAP_CONFIGURED = False @@ -79,9 +79,9 @@ if LDAP_CONFIGURED: BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # Database -configuration.DATABASE.update({'ENGINE': 'django.db.backends.postgresql'}) +netbox.configuration.DATABASE.update({'ENGINE': 'django.db.backends.postgresql'}) DATABASES = { - 'default': configuration.DATABASE, + 'default': netbox.configuration.DATABASE, } # Email diff --git a/netbox/netbox/urls.py b/netbox/netbox/urls.py index 9d01f1773..bbfdee58d 100644 --- a/netbox/netbox/urls.py +++ b/netbox/netbox/urls.py @@ -2,7 +2,7 @@ from django.conf import settings from django.conf.urls import include, url from django.contrib import admin -from views import home, handle_500, trigger_500 +from netbox.views import home, handle_500, trigger_500 from users.views import login, logout diff --git a/netbox/secrets/models.py b/netbox/secrets/models.py index 930d6e032..052050927 100644 --- a/netbox/secrets/models.py +++ b/netbox/secrets/models.py @@ -76,7 +76,7 @@ class UserKey(CreatedUpdatedModel): self.__initial_public_key = self.public_key self.__initial_master_key_cipher = self.master_key_cipher - def __unicode__(self): + def __str__(self): return self.user.username def clean(self, *args, **kwargs): @@ -186,7 +186,7 @@ class SecretRole(models.Model): class Meta: ordering = ['name'] - def __unicode__(self): + def __str__(self): return self.name def get_absolute_url(self): @@ -227,7 +227,7 @@ class Secret(CreatedUpdatedModel): self.plaintext = kwargs.pop('plaintext', None) super(Secret, self).__init__(*args, **kwargs) - def __unicode__(self): + def __str__(self): if self.role and self.device: return u'{} for {}'.format(self.role, self.device) return u'Secret' diff --git a/netbox/tenancy/models.py b/netbox/tenancy/models.py index 4317af196..c690ce7b7 100644 --- a/netbox/tenancy/models.py +++ b/netbox/tenancy/models.py @@ -17,7 +17,7 @@ class TenantGroup(models.Model): class Meta: ordering = ['name'] - def __unicode__(self): + def __str__(self): return self.name def get_absolute_url(self): @@ -39,7 +39,7 @@ class Tenant(CreatedUpdatedModel, CustomFieldModel): class Meta: ordering = ['group', 'name'] - def __unicode__(self): + def __str__(self): return self.name def get_absolute_url(self): diff --git a/netbox/tenancy/views.py b/netbox/tenancy/views.py index 8bc5b8c50..4823eabab 100644 --- a/netbox/tenancy/views.py +++ b/netbox/tenancy/views.py @@ -10,7 +10,7 @@ from utilities.views import ( BulkDeleteView, BulkEditView, BulkImportView, ObjectDeleteView, ObjectEditView, ObjectListView, ) -from models import Tenant, TenantGroup +from .models import Tenant, TenantGroup from . import filters, forms, tables