mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Import unicode_literals
This commit is contained in:
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
from circuits.models import Provider, Circuit, CircuitTermination, CircuitType
|
from circuits.models import Provider, Circuit, CircuitTermination, CircuitType
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from rest_framework import routers
|
from rest_framework import routers
|
||||||
|
|
||||||
from . import views
|
from . import views
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
from django.shortcuts import get_object_or_404
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from rest_framework.decorators import detail_route
|
from rest_framework.decorators import detail_route
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.viewsets import ModelViewSet
|
from rest_framework.viewsets import ModelViewSet
|
||||||
|
|
||||||
|
from django.shortcuts import get_object_or_404
|
||||||
|
|
||||||
from circuits import filters
|
from circuits import filters
|
||||||
from circuits.models import Provider, CircuitTermination, CircuitType, Circuit
|
from circuits.models import Provider, CircuitTermination, CircuitType, Circuit
|
||||||
from extras.models import Graph, GRAPH_TYPE_PROVIDER
|
from extras.models import Graph, GRAPH_TYPE_PROVIDER
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.apps import AppConfig
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import django_filters
|
import django_filters
|
||||||
|
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.db.models import Count
|
from django.db.models import Count
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.contrib.contenttypes.fields import GenericRelation
|
from django.contrib.contenttypes.fields import GenericRelation
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
@ -110,7 +112,7 @@ class Circuit(CreatedUpdatedModel, CustomFieldModel):
|
|||||||
unique_together = ['provider', 'cid']
|
unique_together = ['provider', 'cid']
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return u'{} {}'.format(self.provider, self.cid)
|
return '{} {}'.format(self.provider, self.cid)
|
||||||
|
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return reverse('circuits:circuit', args=[self.pk])
|
return reverse('circuits:circuit', args=[self.pk])
|
||||||
@ -166,7 +168,7 @@ class CircuitTermination(models.Model):
|
|||||||
unique_together = ['circuit', 'term_side']
|
unique_together = ['circuit', 'term_side']
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return u'{} (Side {})'.format(self.circuit, self.get_term_side_display())
|
return '{} (Side {})'.format(self.circuit, self.get_term_side_display())
|
||||||
|
|
||||||
def get_peer_termination(self):
|
def get_peer_termination(self):
|
||||||
peer_side = 'Z' if self.term_side == 'A' else 'A'
|
peer_side = 'Z' if self.term_side == 'A' else 'A'
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.db.models.signals import post_delete, post_save
|
from django.db.models.signals import post_delete, post_save
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import django_tables2 as tables
|
import django_tables2 as tables
|
||||||
from django_tables2.utils import Accessor
|
from django_tables2.utils import Accessor
|
||||||
|
|
||||||
from utilities.tables import BaseTable, SearchTable, ToggleColumn
|
from utilities.tables import BaseTable, SearchTable, ToggleColumn
|
||||||
|
|
||||||
from .models import Circuit, CircuitType, Provider
|
from .models import Circuit, CircuitType, Provider
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
from rest_framework.test import APITestCase
|
from rest_framework.test import APITestCase
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
|
|
||||||
from . import views
|
from . import views
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.contrib.auth.decorators import permission_required
|
from django.contrib.auth.decorators import permission_required
|
||||||
from django.contrib.auth.mixins import PermissionRequiredMixin
|
from django.contrib.auth.mixins import PermissionRequiredMixin
|
||||||
@ -12,7 +14,6 @@ from utilities.forms import ConfirmationForm
|
|||||||
from utilities.views import (
|
from utilities.views import (
|
||||||
BulkDeleteView, BulkEditView, BulkImportView, ObjectDeleteView, ObjectEditView, ObjectListView,
|
BulkDeleteView, BulkEditView, BulkImportView, ObjectDeleteView, ObjectEditView, ObjectListView,
|
||||||
)
|
)
|
||||||
|
|
||||||
from . import filters, forms, tables
|
from . import filters, forms, tables
|
||||||
from .models import Circuit, CircuitTermination, CircuitType, Provider, TERM_SIDE_A, TERM_SIDE_Z
|
from .models import Circuit, CircuitTermination, CircuitType, Provider, TERM_SIDE_A, TERM_SIDE_Z
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from rest_framework.exceptions import APIException
|
from rest_framework.exceptions import APIException
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from rest_framework.validators import UniqueTogetherValidator
|
from rest_framework.validators import UniqueTogetherValidator
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from rest_framework import routers
|
from rest_framework import routers
|
||||||
|
|
||||||
from . import views
|
from . import views
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from rest_framework.decorators import detail_route
|
from rest_framework.decorators import detail_route
|
||||||
from rest_framework.mixins import ListModelMixin
|
from rest_framework.mixins import ListModelMixin
|
||||||
from rest_framework.permissions import IsAuthenticated
|
from rest_framework.permissions import IsAuthenticated
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.apps import AppConfig
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from netaddr import EUI, mac_unix_expanded
|
from netaddr import EUI, mac_unix_expanded
|
||||||
|
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import django_filters
|
import django_filters
|
||||||
from netaddr.core import AddrFormatError
|
from netaddr.core import AddrFormatError
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from netaddr import EUI, AddrFormatError
|
from netaddr import EUI, AddrFormatError
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from mptt.forms import TreeNodeChoiceField
|
from mptt.forms import TreeNodeChoiceField
|
||||||
import re
|
import re
|
||||||
|
|
||||||
@ -16,7 +18,6 @@ from utilities.forms import (
|
|||||||
FilterChoiceField, FlexibleModelChoiceField, Livesearch, SelectWithDisabled, SmallTextarea, SlugField,
|
FilterChoiceField, FlexibleModelChoiceField, Livesearch, SelectWithDisabled, SmallTextarea, SlugField,
|
||||||
FilterTreeNodeMultipleChoiceField,
|
FilterTreeNodeMultipleChoiceField,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .formfields import MACAddressFormField
|
from .formfields import MACAddressFormField
|
||||||
from .models import (
|
from .models import (
|
||||||
DeviceBay, DeviceBayTemplate, CONNECTION_STATUS_CHOICES, CONNECTION_STATUS_PLANNED, CONNECTION_STATUS_CONNECTED,
|
DeviceBay, DeviceBayTemplate, CONNECTION_STATUS_CHOICES, CONNECTION_STATUS_PLANNED, CONNECTION_STATUS_CONNECTED,
|
||||||
@ -610,10 +611,10 @@ class DeviceForm(BootstrapMixin, TenancyForm, CustomFieldForm):
|
|||||||
for family in [4, 6]:
|
for family in [4, 6]:
|
||||||
ip_choices = []
|
ip_choices = []
|
||||||
interface_ips = IPAddress.objects.filter(family=family, interface__device=self.instance)
|
interface_ips = IPAddress.objects.filter(family=family, interface__device=self.instance)
|
||||||
ip_choices += [(ip.id, u'{} ({})'.format(ip.address, ip.interface)) for ip in interface_ips]
|
ip_choices += [(ip.id, '{} ({})'.format(ip.address, ip.interface)) for ip in interface_ips]
|
||||||
nat_ips = IPAddress.objects.filter(family=family, nat_inside__interface__device=self.instance)\
|
nat_ips = IPAddress.objects.filter(family=family, nat_inside__interface__device=self.instance)\
|
||||||
.select_related('nat_inside__interface')
|
.select_related('nat_inside__interface')
|
||||||
ip_choices += [(ip.id, u'{} ({} NAT)'.format(ip.address, ip.nat_inside.interface)) for ip in nat_ips]
|
ip_choices += [(ip.id, '{} ({} NAT)'.format(ip.address, ip.nat_inside.interface)) for ip in nat_ips]
|
||||||
self.fields['primary_ip{}'.format(family)].choices = [(None, '---------')] + ip_choices
|
self.fields['primary_ip{}'.format(family)].choices = [(None, '---------')] + ip_choices
|
||||||
|
|
||||||
# If editing an existing device, exclude it from the list of occupied rack units. This ensures that a device
|
# If editing an existing device, exclude it from the list of occupied rack units. This ensures that a device
|
||||||
@ -804,7 +805,7 @@ def device_status_choices():
|
|||||||
status_counts = {}
|
status_counts = {}
|
||||||
for status in Device.objects.values('status').annotate(count=Count('status')).order_by('status'):
|
for status in Device.objects.values('status').annotate(count=Count('status')).order_by('status'):
|
||||||
status_counts[status['status']] = status['count']
|
status_counts[status['status']] = status['count']
|
||||||
return [(s[0], u'{} ({})'.format(s[1], status_counts.get(s[0], 0))) for s in STATUS_CHOICES]
|
return [(s[0], '{} ({})'.format(s[1], status_counts.get(s[0], 0))) for s in STATUS_CHOICES]
|
||||||
|
|
||||||
|
|
||||||
class DeviceFilterForm(BootstrapMixin, CustomFieldFilterForm):
|
class DeviceFilterForm(BootstrapMixin, CustomFieldFilterForm):
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from itertools import count, groupby
|
from itertools import count, groupby
|
||||||
|
|
||||||
@ -23,7 +24,6 @@ from utilities.fields import ColorField, NullableCharField
|
|||||||
from utilities.managers import NaturalOrderByManager
|
from utilities.managers import NaturalOrderByManager
|
||||||
from utilities.models import CreatedUpdatedModel
|
from utilities.models import CreatedUpdatedModel
|
||||||
from utilities.utils import csv_format
|
from utilities.utils import csv_format
|
||||||
|
|
||||||
from .fields import ASNField, MACAddressField
|
from .fields import ASNField, MACAddressField
|
||||||
|
|
||||||
|
|
||||||
@ -346,7 +346,7 @@ class RackGroup(models.Model):
|
|||||||
]
|
]
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return u'{} - {}'.format(self.site.name, self.name)
|
return '{} - {}'.format(self.site.name, self.name)
|
||||||
|
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return "{}?group_id={}".format(reverse('dcim:rack_list'), self.pk)
|
return "{}?group_id={}".format(reverse('dcim:rack_list'), self.pk)
|
||||||
@ -466,10 +466,10 @@ class Rack(CreatedUpdatedModel, CustomFieldModel):
|
|||||||
@property
|
@property
|
||||||
def display_name(self):
|
def display_name(self):
|
||||||
if self.facility_id:
|
if self.facility_id:
|
||||||
return u"{} ({})".format(self.name, self.facility_id)
|
return "{} ({})".format(self.name, self.facility_id)
|
||||||
elif self.name:
|
elif self.name:
|
||||||
return self.name
|
return self.name
|
||||||
return u""
|
return ""
|
||||||
|
|
||||||
def get_rack_units(self, face=RACK_FACE_FRONT, exclude=None, remove_redundant=False):
|
def get_rack_units(self, face=RACK_FACE_FRONT, exclude=None, remove_redundant=False):
|
||||||
"""
|
"""
|
||||||
@ -569,7 +569,7 @@ class RackReservation(models.Model):
|
|||||||
ordering = ['created']
|
ordering = ['created']
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return u"Reservation for rack {}".format(self.rack)
|
return "Reservation for rack {}".format(self.rack)
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
|
|
||||||
@ -579,7 +579,7 @@ class RackReservation(models.Model):
|
|||||||
invalid_units = [u for u in self.units if u not in self.rack.units]
|
invalid_units = [u for u in self.units if u not in self.rack.units]
|
||||||
if invalid_units:
|
if invalid_units:
|
||||||
raise ValidationError({
|
raise ValidationError({
|
||||||
'units': u"Invalid unit(s) for {}U rack: {}".format(
|
'units': "Invalid unit(s) for {}U rack: {}".format(
|
||||||
self.rack.u_height,
|
self.rack.u_height,
|
||||||
', '.join([str(u) for u in invalid_units]),
|
', '.join([str(u) for u in invalid_units]),
|
||||||
),
|
),
|
||||||
@ -733,7 +733,7 @@ class DeviceType(models.Model, CustomFieldModel):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def full_name(self):
|
def full_name(self):
|
||||||
return u'{} {}'.format(self.manufacturer.name, self.model)
|
return '{} {}'.format(self.manufacturer.name, self.model)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_parent_device(self):
|
def is_parent_device(self):
|
||||||
@ -1106,8 +1106,8 @@ class Device(CreatedUpdatedModel, CustomFieldModel):
|
|||||||
if self.name:
|
if self.name:
|
||||||
return self.name
|
return self.name
|
||||||
elif hasattr(self, 'device_type'):
|
elif hasattr(self, 'device_type'):
|
||||||
return u"{}".format(self.device_type)
|
return "{}".format(self.device_type)
|
||||||
return u""
|
return ""
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def identifier(self):
|
def identifier(self):
|
||||||
@ -1320,7 +1320,7 @@ class Interface(models.Model):
|
|||||||
# An interface's LAG must belong to the same device
|
# An interface's LAG must belong to the same device
|
||||||
if self.lag and self.lag.device != self.device:
|
if self.lag and self.lag.device != self.device:
|
||||||
raise ValidationError({
|
raise ValidationError({
|
||||||
'lag': u"The selected LAG interface ({}) belongs to a different device ({}).".format(
|
'lag': "The selected LAG interface ({}) belongs to a different device ({}).".format(
|
||||||
self.lag.name, self.lag.device.name
|
self.lag.name, self.lag.device.name
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@ -1328,14 +1328,14 @@ class Interface(models.Model):
|
|||||||
# A virtual interface cannot have a parent LAG
|
# A virtual interface cannot have a parent LAG
|
||||||
if self.form_factor in VIRTUAL_IFACE_TYPES and self.lag is not None:
|
if self.form_factor in VIRTUAL_IFACE_TYPES and self.lag is not None:
|
||||||
raise ValidationError({
|
raise ValidationError({
|
||||||
'lag': u"{} interfaces cannot have a parent LAG interface.".format(self.get_form_factor_display())
|
'lag': "{} interfaces cannot have a parent LAG interface.".format(self.get_form_factor_display())
|
||||||
})
|
})
|
||||||
|
|
||||||
# Only a LAG can have LAG members
|
# Only a LAG can have LAG members
|
||||||
if self.form_factor != IFACE_FF_LAG and self.member_interfaces.exists():
|
if self.form_factor != IFACE_FF_LAG and self.member_interfaces.exists():
|
||||||
raise ValidationError({
|
raise ValidationError({
|
||||||
'form_factor': "Cannot change interface form factor; it has LAG members ({}).".format(
|
'form_factor': "Cannot change interface form factor; it has LAG members ({}).".format(
|
||||||
u", ".join([iface.name for iface in self.member_interfaces.all()])
|
", ".join([iface.name for iface in self.member_interfaces.all()])
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -1428,7 +1428,7 @@ class DeviceBay(models.Model):
|
|||||||
unique_together = ['device', 'name']
|
unique_together = ['device', 'name']
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return u'{} - {}'.format(self.device.name, self.name)
|
return '{} - {}'.format(self.device.name, self.name)
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
|
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import django_tables2 as tables
|
import django_tables2 as tables
|
||||||
from django_tables2.utils import Accessor
|
from django_tables2.utils import Accessor
|
||||||
|
|
||||||
from utilities.tables import BaseTable, SearchTable, ToggleColumn
|
from utilities.tables import BaseTable, SearchTable, ToggleColumn
|
||||||
|
|
||||||
from .models import (
|
from .models import (
|
||||||
ConsolePort, ConsolePortTemplate, ConsoleServerPortTemplate, Device, DeviceBayTemplate, DeviceRole, DeviceType,
|
ConsolePort, ConsolePortTemplate, ConsoleServerPortTemplate, Device, DeviceBayTemplate, DeviceRole, DeviceType,
|
||||||
Interface, InterfaceTemplate, Manufacturer, Platform, PowerOutletTemplate, PowerPort, PowerPortTemplate, Rack,
|
Interface, InterfaceTemplate, Manufacturer, Platform, PowerOutletTemplate, PowerPort, PowerPortTemplate, Rack,
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
from rest_framework.test import APITestCase
|
from rest_framework.test import APITestCase
|
||||||
|
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
from dcim.forms import *
|
from dcim.forms import *
|
||||||
from dcim.models import *
|
from dcim.models import *
|
||||||
|
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
from dcim.models import *
|
from dcim.models import *
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
|
|
||||||
|
from extras.views import ImageAttachmentEditView
|
||||||
from ipam.views import ServiceEditView
|
from ipam.views import ServiceEditView
|
||||||
from secrets.views import secret_add
|
from secrets.views import secret_add
|
||||||
|
|
||||||
from extras.views import ImageAttachmentEditView
|
|
||||||
from .models import Device, Rack, Site
|
from .models import Device, Rack, Site
|
||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
import re
|
import re
|
||||||
from natsort import natsorted
|
from natsort import natsorted
|
||||||
@ -24,7 +25,6 @@ from utilities.paginator import EnhancedPaginator
|
|||||||
from utilities.views import (
|
from utilities.views import (
|
||||||
BulkDeleteView, BulkEditView, BulkImportView, ObjectDeleteView, ObjectEditView, ObjectListView,
|
BulkDeleteView, BulkEditView, BulkImportView, ObjectDeleteView, ObjectEditView, ObjectListView,
|
||||||
)
|
)
|
||||||
|
|
||||||
from . import filters, forms, tables
|
from . import filters, forms, tables
|
||||||
from .models import (
|
from .models import (
|
||||||
CONNECTION_STATUS_CONNECTED, ConsolePort, ConsolePortTemplate, ConsoleServerPort, ConsoleServerPortTemplate, Device,
|
CONNECTION_STATUS_CONNECTED, ConsolePort, ConsolePortTemplate, ConsoleServerPort, ConsoleServerPortTemplate, Device,
|
||||||
@ -109,11 +109,11 @@ class ComponentCreateView(View):
|
|||||||
if field == 'name':
|
if field == 'name':
|
||||||
field = 'name_pattern'
|
field = 'name_pattern'
|
||||||
for e in errors:
|
for e in errors:
|
||||||
form.add_error(field, u'{}: {}'.format(name, ', '.join(e)))
|
form.add_error(field, '{}: {}'.format(name, ', '.join(e)))
|
||||||
|
|
||||||
if not form.errors:
|
if not form.errors:
|
||||||
self.model.objects.bulk_create(new_components)
|
self.model.objects.bulk_create(new_components)
|
||||||
messages.success(request, u"Added {} {} to {}.".format(
|
messages.success(request, "Added {} {} to {}.".format(
|
||||||
len(new_components), self.model._meta.verbose_name_plural, parent
|
len(new_components), self.model._meta.verbose_name_plural, parent
|
||||||
))
|
))
|
||||||
if '_addanother' in request.POST:
|
if '_addanother' in request.POST:
|
||||||
@ -930,7 +930,7 @@ def consoleport_connect(request, pk):
|
|||||||
form = forms.ConsolePortConnectionForm(request.POST, instance=consoleport)
|
form = forms.ConsolePortConnectionForm(request.POST, instance=consoleport)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
consoleport = form.save()
|
consoleport = form.save()
|
||||||
msg = u'Connected <a href="{}">{}</a> {} to <a href="{}">{}</a> {}'.format(
|
msg = 'Connected <a href="{}">{}</a> {} to <a href="{}">{}</a> {}'.format(
|
||||||
consoleport.device.get_absolute_url(),
|
consoleport.device.get_absolute_url(),
|
||||||
escape(consoleport.device),
|
escape(consoleport.device),
|
||||||
escape(consoleport.name),
|
escape(consoleport.name),
|
||||||
@ -964,7 +964,7 @@ def consoleport_disconnect(request, pk):
|
|||||||
|
|
||||||
if not consoleport.cs_port:
|
if not consoleport.cs_port:
|
||||||
messages.warning(
|
messages.warning(
|
||||||
request, u"Cannot disconnect console port {}: It is not connected to anything.".format(consoleport)
|
request, "Cannot disconnect console port {}: It is not connected to anything.".format(consoleport)
|
||||||
)
|
)
|
||||||
return redirect('dcim:device', pk=consoleport.device.pk)
|
return redirect('dcim:device', pk=consoleport.device.pk)
|
||||||
|
|
||||||
@ -975,7 +975,7 @@ def consoleport_disconnect(request, pk):
|
|||||||
consoleport.cs_port = None
|
consoleport.cs_port = None
|
||||||
consoleport.connection_status = None
|
consoleport.connection_status = None
|
||||||
consoleport.save()
|
consoleport.save()
|
||||||
msg = u'Disconnected <a href="{}">{}</a> {} from <a href="{}">{}</a> {}'.format(
|
msg = 'Disconnected <a href="{}">{}</a> {} from <a href="{}">{}</a> {}'.format(
|
||||||
consoleport.device.get_absolute_url(),
|
consoleport.device.get_absolute_url(),
|
||||||
escape(consoleport.device),
|
escape(consoleport.device),
|
||||||
escape(consoleport.name),
|
escape(consoleport.name),
|
||||||
@ -1047,7 +1047,7 @@ def consoleserverport_connect(request, pk):
|
|||||||
consoleport.cs_port = consoleserverport
|
consoleport.cs_port = consoleserverport
|
||||||
consoleport.connection_status = form.cleaned_data['connection_status']
|
consoleport.connection_status = form.cleaned_data['connection_status']
|
||||||
consoleport.save()
|
consoleport.save()
|
||||||
msg = u'Connected <a href="{}">{}</a> {} to <a href="{}">{}</a> {}'.format(
|
msg = 'Connected <a href="{}">{}</a> {} to <a href="{}">{}</a> {}'.format(
|
||||||
consoleport.device.get_absolute_url(),
|
consoleport.device.get_absolute_url(),
|
||||||
escape(consoleport.device),
|
escape(consoleport.device),
|
||||||
escape(consoleport.name),
|
escape(consoleport.name),
|
||||||
@ -1081,7 +1081,7 @@ def consoleserverport_disconnect(request, pk):
|
|||||||
|
|
||||||
if not hasattr(consoleserverport, 'connected_console'):
|
if not hasattr(consoleserverport, 'connected_console'):
|
||||||
messages.warning(
|
messages.warning(
|
||||||
request, u"Cannot disconnect console server port {}: Nothing is connected to it.".format(consoleserverport)
|
request, "Cannot disconnect console server port {}: Nothing is connected to it.".format(consoleserverport)
|
||||||
)
|
)
|
||||||
return redirect('dcim:device', pk=consoleserverport.device.pk)
|
return redirect('dcim:device', pk=consoleserverport.device.pk)
|
||||||
|
|
||||||
@ -1092,7 +1092,7 @@ def consoleserverport_disconnect(request, pk):
|
|||||||
consoleport.cs_port = None
|
consoleport.cs_port = None
|
||||||
consoleport.connection_status = None
|
consoleport.connection_status = None
|
||||||
consoleport.save()
|
consoleport.save()
|
||||||
msg = u'Disconnected <a href="{}">{}</a> {} from <a href="{}">{}</a> {}'.format(
|
msg = 'Disconnected <a href="{}">{}</a> {} from <a href="{}">{}</a> {}'.format(
|
||||||
consoleport.device.get_absolute_url(),
|
consoleport.device.get_absolute_url(),
|
||||||
escape(consoleport.device),
|
escape(consoleport.device),
|
||||||
escape(consoleport.name),
|
escape(consoleport.name),
|
||||||
@ -1153,7 +1153,7 @@ def powerport_connect(request, pk):
|
|||||||
form = forms.PowerPortConnectionForm(request.POST, instance=powerport)
|
form = forms.PowerPortConnectionForm(request.POST, instance=powerport)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
powerport = form.save()
|
powerport = form.save()
|
||||||
msg = u'Connected <a href="{}">{}</a> {} to <a href="{}">{}</a> {}'.format(
|
msg = 'Connected <a href="{}">{}</a> {} to <a href="{}">{}</a> {}'.format(
|
||||||
powerport.device.get_absolute_url(),
|
powerport.device.get_absolute_url(),
|
||||||
escape(powerport.device),
|
escape(powerport.device),
|
||||||
escape(powerport.name),
|
escape(powerport.name),
|
||||||
@ -1187,7 +1187,7 @@ def powerport_disconnect(request, pk):
|
|||||||
|
|
||||||
if not powerport.power_outlet:
|
if not powerport.power_outlet:
|
||||||
messages.warning(
|
messages.warning(
|
||||||
request, u"Cannot disconnect power port {}: It is not connected to an outlet.".format(powerport)
|
request, "Cannot disconnect power port {}: It is not connected to an outlet.".format(powerport)
|
||||||
)
|
)
|
||||||
return redirect('dcim:device', pk=powerport.device.pk)
|
return redirect('dcim:device', pk=powerport.device.pk)
|
||||||
|
|
||||||
@ -1198,7 +1198,7 @@ def powerport_disconnect(request, pk):
|
|||||||
powerport.power_outlet = None
|
powerport.power_outlet = None
|
||||||
powerport.connection_status = None
|
powerport.connection_status = None
|
||||||
powerport.save()
|
powerport.save()
|
||||||
msg = u'Disconnected <a href="{}">{}</a> {} from <a href="{}">{}</a> {}'.format(
|
msg = 'Disconnected <a href="{}">{}</a> {} from <a href="{}">{}</a> {}'.format(
|
||||||
powerport.device.get_absolute_url(),
|
powerport.device.get_absolute_url(),
|
||||||
escape(powerport.device),
|
escape(powerport.device),
|
||||||
escape(powerport.name),
|
escape(powerport.name),
|
||||||
@ -1270,7 +1270,7 @@ def poweroutlet_connect(request, pk):
|
|||||||
powerport.power_outlet = poweroutlet
|
powerport.power_outlet = poweroutlet
|
||||||
powerport.connection_status = form.cleaned_data['connection_status']
|
powerport.connection_status = form.cleaned_data['connection_status']
|
||||||
powerport.save()
|
powerport.save()
|
||||||
msg = u'Connected <a href="{}">{}</a> {} to <a href="{}">{}</a> {}'.format(
|
msg = 'Connected <a href="{}">{}</a> {} to <a href="{}">{}</a> {}'.format(
|
||||||
powerport.device.get_absolute_url(),
|
powerport.device.get_absolute_url(),
|
||||||
escape(powerport.device),
|
escape(powerport.device),
|
||||||
escape(powerport.name),
|
escape(powerport.name),
|
||||||
@ -1304,7 +1304,7 @@ def poweroutlet_disconnect(request, pk):
|
|||||||
|
|
||||||
if not hasattr(poweroutlet, 'connected_port'):
|
if not hasattr(poweroutlet, 'connected_port'):
|
||||||
messages.warning(
|
messages.warning(
|
||||||
request, u"Cannot disconnect power outlet {}: Nothing is connected to it.".format(poweroutlet)
|
request, "Cannot disconnect power outlet {}: Nothing is connected to it.".format(poweroutlet)
|
||||||
)
|
)
|
||||||
return redirect('dcim:device', pk=poweroutlet.device.pk)
|
return redirect('dcim:device', pk=poweroutlet.device.pk)
|
||||||
|
|
||||||
@ -1315,7 +1315,7 @@ def poweroutlet_disconnect(request, pk):
|
|||||||
powerport.power_outlet = None
|
powerport.power_outlet = None
|
||||||
powerport.connection_status = None
|
powerport.connection_status = None
|
||||||
powerport.save()
|
powerport.save()
|
||||||
msg = u'Disconnected <a href="{}">{}</a> {} from <a href="{}">{}</a> {}'.format(
|
msg = 'Disconnected <a href="{}">{}</a> {} from <a href="{}">{}</a> {}'.format(
|
||||||
powerport.device.get_absolute_url(),
|
powerport.device.get_absolute_url(),
|
||||||
escape(powerport.device),
|
escape(powerport.device),
|
||||||
escape(powerport.name),
|
escape(powerport.name),
|
||||||
@ -1429,7 +1429,7 @@ def devicebay_populate(request, pk):
|
|||||||
device_bay.save()
|
device_bay.save()
|
||||||
|
|
||||||
if not form.errors:
|
if not form.errors:
|
||||||
messages.success(request, u"Added {} to {}.".format(device_bay.installed_device, device_bay))
|
messages.success(request, "Added {} to {}.".format(device_bay.installed_device, device_bay))
|
||||||
return redirect('dcim:device', pk=device_bay.device.pk)
|
return redirect('dcim:device', pk=device_bay.device.pk)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@ -1453,7 +1453,7 @@ def devicebay_depopulate(request, pk):
|
|||||||
removed_device = device_bay.installed_device
|
removed_device = device_bay.installed_device
|
||||||
device_bay.installed_device = None
|
device_bay.installed_device = None
|
||||||
device_bay.save()
|
device_bay.save()
|
||||||
messages.success(request, u"{} has been removed from {}.".format(removed_device, device_bay))
|
messages.success(request, "{} has been removed from {}.".format(removed_device, device_bay))
|
||||||
return redirect('dcim:device', pk=device_bay.device.pk)
|
return redirect('dcim:device', pk=device_bay.device.pk)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@ -1516,11 +1516,11 @@ class DeviceBulkAddComponentView(View):
|
|||||||
else:
|
else:
|
||||||
for field, errors in component_form.errors.as_data().items():
|
for field, errors in component_form.errors.as_data().items():
|
||||||
for e in errors:
|
for e in errors:
|
||||||
form.add_error(field, u'{} {}: {}'.format(device, name, ', '.join(e)))
|
form.add_error(field, '{} {}: {}'.format(device, name, ', '.join(e)))
|
||||||
|
|
||||||
if not form.errors:
|
if not form.errors:
|
||||||
self.model.objects.bulk_create(new_components)
|
self.model.objects.bulk_create(new_components)
|
||||||
messages.success(request, u"Added {} {} to {} devices.".format(
|
messages.success(request, "Added {} {} to {} devices.".format(
|
||||||
len(new_components), self.model._meta.verbose_name_plural, len(form.cleaned_data['pk'])
|
len(new_components), self.model._meta.verbose_name_plural, len(form.cleaned_data['pk'])
|
||||||
))
|
))
|
||||||
return redirect('dcim:device_list')
|
return redirect('dcim:device_list')
|
||||||
@ -1530,7 +1530,7 @@ class DeviceBulkAddComponentView(View):
|
|||||||
|
|
||||||
selected_devices = Device.objects.filter(pk__in=pk_list)
|
selected_devices = Device.objects.filter(pk__in=pk_list)
|
||||||
if not selected_devices:
|
if not selected_devices:
|
||||||
messages.warning(request, u"No devices were selected.")
|
messages.warning(request, "No devices were selected.")
|
||||||
return redirect('dcim:device_list')
|
return redirect('dcim:device_list')
|
||||||
|
|
||||||
return render(request, 'dcim/device_bulk_add_component.html', {
|
return render(request, 'dcim/device_bulk_add_component.html', {
|
||||||
@ -1592,7 +1592,7 @@ def interfaceconnection_add(request, pk):
|
|||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
|
|
||||||
interfaceconnection = form.save()
|
interfaceconnection = form.save()
|
||||||
msg = u'Connected <a href="{}">{}</a> {} to <a href="{}">{}</a> {}'.format(
|
msg = 'Connected <a href="{}">{}</a> {} to <a href="{}">{}</a> {}'.format(
|
||||||
interfaceconnection.interface_a.device.get_absolute_url(),
|
interfaceconnection.interface_a.device.get_absolute_url(),
|
||||||
escape(interfaceconnection.interface_a.device),
|
escape(interfaceconnection.interface_a.device),
|
||||||
escape(interfaceconnection.interface_a.name),
|
escape(interfaceconnection.interface_a.name),
|
||||||
@ -1640,7 +1640,7 @@ def interfaceconnection_delete(request, pk):
|
|||||||
form = forms.InterfaceConnectionDeletionForm(request.POST)
|
form = forms.InterfaceConnectionDeletionForm(request.POST)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
interfaceconnection.delete()
|
interfaceconnection.delete()
|
||||||
msg = u'Disconnected <a href="{}">{}</a> {} from <a href="{}">{}</a> {}'.format(
|
msg = 'Disconnected <a href="{}">{}</a> {} from <a href="{}">{}</a> {}'.format(
|
||||||
interfaceconnection.interface_a.device.get_absolute_url(),
|
interfaceconnection.interface_a.device.get_absolute_url(),
|
||||||
escape(interfaceconnection.interface_a.device),
|
escape(interfaceconnection.interface_a.device),
|
||||||
escape(interfaceconnection.interface_a.name),
|
escape(interfaceconnection.interface_a.name),
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
from django.contrib.contenttypes.models import ContentType
|
from __future__ import unicode_literals
|
||||||
from django.db import transaction
|
|
||||||
|
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from rest_framework.exceptions import ValidationError
|
from rest_framework.exceptions import ValidationError
|
||||||
|
|
||||||
|
from django.contrib.contenttypes.models import ContentType
|
||||||
|
from django.db import transaction
|
||||||
|
|
||||||
from extras.models import CF_TYPE_SELECT, CustomField, CustomFieldChoice, CustomFieldValue
|
from extras.models import CF_TYPE_SELECT, CustomField, CustomFieldChoice, CustomFieldValue
|
||||||
|
|
||||||
|
|
||||||
@ -25,14 +27,14 @@ class CustomFieldsSerializer(serializers.BaseSerializer):
|
|||||||
|
|
||||||
# Validate custom field name
|
# Validate custom field name
|
||||||
if field_name not in custom_fields:
|
if field_name not in custom_fields:
|
||||||
raise ValidationError(u"Invalid custom field for {} objects: {}".format(content_type, field_name))
|
raise ValidationError("Invalid custom field for {} objects: {}".format(content_type, field_name))
|
||||||
|
|
||||||
# Validate selected choice
|
# Validate selected choice
|
||||||
cf = custom_fields[field_name]
|
cf = custom_fields[field_name]
|
||||||
if cf.type == CF_TYPE_SELECT:
|
if cf.type == CF_TYPE_SELECT:
|
||||||
valid_choices = [c.pk for c in cf.choices.all()]
|
valid_choices = [c.pk for c in cf.choices.all()]
|
||||||
if value not in valid_choices:
|
if value not in valid_choices:
|
||||||
raise ValidationError(u"Invalid choice ({}) for field {}".format(value, field_name))
|
raise ValidationError("Invalid choice ({}) for field {}".format(value, field_name))
|
||||||
|
|
||||||
# Check for missing required fields
|
# Check for missing required fields
|
||||||
missing_fields = []
|
missing_fields = []
|
||||||
@ -40,7 +42,7 @@ class CustomFieldsSerializer(serializers.BaseSerializer):
|
|||||||
if field.required and field_name not in data:
|
if field.required and field_name not in data:
|
||||||
missing_fields.append(field_name)
|
missing_fields.append(field_name)
|
||||||
if missing_fields:
|
if missing_fields:
|
||||||
raise ValidationError(u"Missing required fields: {}".format(u", ".join(missing_fields)))
|
raise ValidationError("Missing required fields: {}".format(u", ".join(missing_fields)))
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
from rest_framework import serializers
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
|
|
||||||
|
from rest_framework import serializers
|
||||||
|
|
||||||
from dcim.api.serializers import NestedDeviceSerializer, NestedRackSerializer, NestedSiteSerializer
|
from dcim.api.serializers import NestedDeviceSerializer, NestedRackSerializer, NestedSiteSerializer
|
||||||
from dcim.models import Device, Rack, Site
|
from dcim.models import Device, Rack, Site
|
||||||
from extras.models import (
|
from extras.models import (
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from rest_framework import routers
|
from rest_framework import routers
|
||||||
|
|
||||||
from . import views
|
from . import views
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from rest_framework.decorators import detail_route
|
from rest_framework.decorators import detail_route
|
||||||
from rest_framework.viewsets import ModelViewSet, ReadOnlyModelViewSet
|
from rest_framework.viewsets import ModelViewSet, ReadOnlyModelViewSet
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import django_filters
|
import django_filters
|
||||||
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
@ -104,7 +105,7 @@ class CustomFieldForm(forms.ModelForm):
|
|||||||
obj_id=self.instance.pk)
|
obj_id=self.instance.pk)
|
||||||
except CustomFieldValue.DoesNotExist:
|
except CustomFieldValue.DoesNotExist:
|
||||||
# Skip this field if none exists already and its value is empty
|
# Skip this field if none exists already and its value is empty
|
||||||
if self.cleaned_data[field_name] in [None, u'']:
|
if self.cleaned_data[field_name] in [None, '']:
|
||||||
continue
|
continue
|
||||||
cfv = CustomFieldValue(
|
cfv = CustomFieldValue(
|
||||||
field=self.fields[field_name].model,
|
field=self.fields[field_name].model,
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from getpass import getpass
|
from getpass import getpass
|
||||||
from ncclient.transport.errors import AuthenticationError
|
from ncclient.transport.errors import AuthenticationError
|
||||||
from paramiko import AuthenticationException
|
from paramiko import AuthenticationException
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from datetime import date
|
from datetime import date
|
||||||
import graphviz
|
import graphviz
|
||||||
@ -175,7 +176,7 @@ class CustomFieldValue(models.Model):
|
|||||||
unique_together = ['field', 'obj_type', 'obj_id']
|
unique_together = ['field', 'obj_type', 'obj_id']
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return u'{} {}'.format(self.obj, self.field)
|
return '{} {}'.format(self.obj, self.field)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def value(self):
|
def value(self):
|
||||||
@ -269,7 +270,7 @@ class ExportTemplate(models.Model):
|
|||||||
]
|
]
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return u'{}: {}'.format(self.content_type, self.name)
|
return '{}: {}'.format(self.content_type, self.name)
|
||||||
|
|
||||||
def to_response(self, context_dict, filename):
|
def to_response(self, context_dict, filename):
|
||||||
"""
|
"""
|
||||||
@ -387,7 +388,7 @@ def image_upload(instance, filename):
|
|||||||
elif instance.name:
|
elif instance.name:
|
||||||
filename = instance.name
|
filename = instance.name
|
||||||
|
|
||||||
return u'{}{}_{}_{}'.format(path, instance.content_type.name, instance.object_id, filename)
|
return '{}{}_{}_{}'.format(path, instance.content_type.name, instance.object_id, filename)
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
@ -503,8 +504,8 @@ class UserAction(models.Model):
|
|||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
if self.message:
|
if self.message:
|
||||||
return u'{} {}'.format(self.user, self.message)
|
return '{} {}'.format(self.user, self.message)
|
||||||
return u'{} {} {}'.format(self.user, self.get_action_display(), self.content_type)
|
return '{} {} {}'.format(self.user, self.get_action_display(), self.content_type)
|
||||||
|
|
||||||
def icon(self):
|
def icon(self):
|
||||||
if self.action in [ACTION_CREATE, ACTION_BULK_CREATE, ACTION_IMPORT]:
|
if self.action in [ACTION_CREATE, ACTION_BULK_CREATE, ACTION_IMPORT]:
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
import re
|
||||||
|
import time
|
||||||
|
|
||||||
from ncclient import manager
|
from ncclient import manager
|
||||||
import paramiko
|
import paramiko
|
||||||
import re
|
|
||||||
import xmltodict
|
import xmltodict
|
||||||
import time
|
|
||||||
|
|
||||||
|
|
||||||
CONNECT_TIMEOUT = 5 # seconds
|
CONNECT_TIMEOUT = 5 # seconds
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
from rest_framework.test import APITestCase
|
from rest_framework.test import APITestCase
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
from datetime import date
|
from datetime import date
|
||||||
|
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
@ -9,7 +10,6 @@ from django.test import TestCase
|
|||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
from dcim.models import Site
|
from dcim.models import Site
|
||||||
|
|
||||||
from extras.models import (
|
from extras.models import (
|
||||||
CustomField, CustomFieldValue, CustomFieldChoice, CF_TYPE_TEXT, CF_TYPE_INTEGER, CF_TYPE_BOOLEAN, CF_TYPE_DATE,
|
CustomField, CustomFieldValue, CustomFieldChoice, CF_TYPE_TEXT, CF_TYPE_INTEGER, CF_TYPE_BOOLEAN, CF_TYPE_DATE,
|
||||||
CF_TYPE_SELECT, CF_TYPE_URL,
|
CF_TYPE_SELECT, CF_TYPE_URL,
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
|
|
||||||
from extras import views
|
from extras import views
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.contrib.auth.mixins import PermissionRequiredMixin
|
from django.contrib.auth.mixins import PermissionRequiredMixin
|
||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from rest_framework.validators import UniqueTogetherValidator
|
from rest_framework.validators import UniqueTogetherValidator
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from rest_framework import routers
|
from rest_framework import routers
|
||||||
|
|
||||||
from . import views
|
from . import views
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from rest_framework.viewsets import ModelViewSet
|
from rest_framework.viewsets import ModelViewSet
|
||||||
|
|
||||||
from ipam.models import Aggregate, IPAddress, Prefix, RIR, Role, Service, VLAN, VLANGroup, VRF
|
from ipam.models import Aggregate, IPAddress, Prefix, RIR, Role, Service, VLAN, VLANGroup, VRF
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.apps import AppConfig
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from netaddr import IPNetwork
|
from netaddr import IPNetwork
|
||||||
|
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import django_filters
|
import django_filters
|
||||||
from netaddr import IPNetwork
|
from netaddr import IPNetwork
|
||||||
from netaddr.core import AddrFormatError
|
from netaddr.core import AddrFormatError
|
||||||
@ -8,7 +10,6 @@ from dcim.models import Site, Device, Interface
|
|||||||
from extras.filters import CustomFieldFilterSet
|
from extras.filters import CustomFieldFilterSet
|
||||||
from tenancy.models import Tenant
|
from tenancy.models import Tenant
|
||||||
from utilities.filters import NullableModelMultipleChoiceFilter, NumericInFilter
|
from utilities.filters import NullableModelMultipleChoiceFilter, NumericInFilter
|
||||||
|
|
||||||
from .models import (
|
from .models import (
|
||||||
Aggregate, IPAddress, IPADDRESS_STATUS_CHOICES, Prefix, PREFIX_STATUS_CHOICES, RIR, Role, Service, VLAN,
|
Aggregate, IPAddress, IPADDRESS_STATUS_CHOICES, Prefix, PREFIX_STATUS_CHOICES, RIR, Role, Service, VLAN,
|
||||||
VLAN_STATUS_CHOICES, VLANGroup, VRF,
|
VLAN_STATUS_CHOICES, VLANGroup, VRF,
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from netaddr import IPNetwork, AddrFormatError
|
from netaddr import IPNetwork, AddrFormatError
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.db.models import Count
|
from django.db.models import Count
|
||||||
@ -10,7 +12,6 @@ from utilities.forms import (
|
|||||||
APISelect, BootstrapMixin, BulkEditNullBooleanSelect, BulkImportForm, ChainedModelChoiceField, CSVDataField,
|
APISelect, BootstrapMixin, BulkEditNullBooleanSelect, BulkImportForm, ChainedModelChoiceField, CSVDataField,
|
||||||
ExpandableIPAddressField, FilterChoiceField, Livesearch, ReturnURLForm, SlugField, add_blank_choice,
|
ExpandableIPAddressField, FilterChoiceField, Livesearch, ReturnURLForm, SlugField, add_blank_choice,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .models import (
|
from .models import (
|
||||||
Aggregate, IPAddress, IPADDRESS_STATUS_CHOICES, Prefix, PREFIX_STATUS_CHOICES, RIR, Role, Service, VLAN,
|
Aggregate, IPAddress, IPADDRESS_STATUS_CHOICES, Prefix, PREFIX_STATUS_CHOICES, RIR, Role, Service, VLAN,
|
||||||
VLANGroup, VLAN_STATUS_CHOICES, VRF,
|
VLANGroup, VLAN_STATUS_CHOICES, VRF,
|
||||||
@ -270,7 +271,7 @@ def prefix_status_choices():
|
|||||||
status_counts = {}
|
status_counts = {}
|
||||||
for status in Prefix.objects.values('status').annotate(count=Count('status')).order_by('status'):
|
for status in Prefix.objects.values('status').annotate(count=Count('status')).order_by('status'):
|
||||||
status_counts[status['status']] = status['count']
|
status_counts[status['status']] = status['count']
|
||||||
return [(s[0], u'{} ({})'.format(s[1], status_counts.get(s[0], 0))) for s in PREFIX_STATUS_CHOICES]
|
return [(s[0], '{} ({})'.format(s[1], status_counts.get(s[0], 0))) for s in PREFIX_STATUS_CHOICES]
|
||||||
|
|
||||||
|
|
||||||
class PrefixFilterForm(BootstrapMixin, CustomFieldFilterForm):
|
class PrefixFilterForm(BootstrapMixin, CustomFieldFilterForm):
|
||||||
@ -567,7 +568,7 @@ def ipaddress_status_choices():
|
|||||||
status_counts = {}
|
status_counts = {}
|
||||||
for status in IPAddress.objects.values('status').annotate(count=Count('status')).order_by('status'):
|
for status in IPAddress.objects.values('status').annotate(count=Count('status')).order_by('status'):
|
||||||
status_counts[status['status']] = status['count']
|
status_counts[status['status']] = status['count']
|
||||||
return [(s[0], u'{} ({})'.format(s[1], status_counts.get(s[0], 0))) for s in IPADDRESS_STATUS_CHOICES]
|
return [(s[0], '{} ({})'.format(s[1], status_counts.get(s[0], 0))) for s in IPADDRESS_STATUS_CHOICES]
|
||||||
|
|
||||||
|
|
||||||
class IPAddressFilterForm(BootstrapMixin, CustomFieldFilterForm):
|
class IPAddressFilterForm(BootstrapMixin, CustomFieldFilterForm):
|
||||||
@ -720,7 +721,7 @@ def vlan_status_choices():
|
|||||||
status_counts = {}
|
status_counts = {}
|
||||||
for status in VLAN.objects.values('status').annotate(count=Count('status')).order_by('status'):
|
for status in VLAN.objects.values('status').annotate(count=Count('status')).order_by('status'):
|
||||||
status_counts[status['status']] = status['count']
|
status_counts[status['status']] = status['count']
|
||||||
return [(s[0], u'{} ({})'.format(s[1], status_counts.get(s[0], 0))) for s in VLAN_STATUS_CHOICES]
|
return [(s[0], '{} ({})'.format(s[1], status_counts.get(s[0], 0))) for s in VLAN_STATUS_CHOICES]
|
||||||
|
|
||||||
|
|
||||||
class VLANFilterForm(BootstrapMixin, CustomFieldFilterForm):
|
class VLANFilterForm(BootstrapMixin, CustomFieldFilterForm):
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.db.models import Lookup, Transform, IntegerField
|
from django.db.models import Lookup, Transform, IntegerField
|
||||||
from django.db.models.lookups import BuiltinLookup
|
from django.db.models.lookups import BuiltinLookup
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from netaddr import IPNetwork, cidr_merge
|
from netaddr import IPNetwork, cidr_merge
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
@ -15,7 +17,6 @@ from tenancy.models import Tenant
|
|||||||
from utilities.models import CreatedUpdatedModel
|
from utilities.models import CreatedUpdatedModel
|
||||||
from utilities.sql import NullsFirstQuerySet
|
from utilities.sql import NullsFirstQuerySet
|
||||||
from utilities.utils import csv_format
|
from utilities.utils import csv_format
|
||||||
|
|
||||||
from .fields import IPNetworkField, IPAddressField
|
from .fields import IPNetworkField, IPAddressField
|
||||||
|
|
||||||
|
|
||||||
@ -499,7 +500,7 @@ class VLANGroup(models.Model):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
if self.site is None:
|
if self.site is None:
|
||||||
return self.name
|
return self.name
|
||||||
return u'{} - {}'.format(self.site.name, self.name)
|
return '{} - {}'.format(self.site.name, self.name)
|
||||||
|
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return "{}?group_id={}".format(reverse('ipam:vlan_list'), self.pk)
|
return "{}?group_id={}".format(reverse('ipam:vlan_list'), self.pk)
|
||||||
@ -566,7 +567,7 @@ class VLAN(CreatedUpdatedModel, CustomFieldModel):
|
|||||||
@property
|
@property
|
||||||
def display_name(self):
|
def display_name(self):
|
||||||
if self.vid and self.name:
|
if self.vid and self.name:
|
||||||
return u"{} ({})".format(self.vid, self.name)
|
return "{} ({})".format(self.vid, self.name)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_status_class(self):
|
def get_status_class(self):
|
||||||
@ -593,4 +594,4 @@ class Service(CreatedUpdatedModel):
|
|||||||
unique_together = ['device', 'protocol', 'port']
|
unique_together = ['device', 'protocol', 'port']
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return u'{} ({}/{})'.format(self.name, self.port, self.get_protocol_display())
|
return '{} ({}/{})'.format(self.name, self.port, self.get_protocol_display())
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import django_tables2 as tables
|
import django_tables2 as tables
|
||||||
from django_tables2.utils import Accessor
|
from django_tables2.utils import Accessor
|
||||||
|
|
||||||
from utilities.tables import BaseTable, SearchTable, ToggleColumn
|
from utilities.tables import BaseTable, SearchTable, ToggleColumn
|
||||||
|
|
||||||
from .models import Aggregate, IPAddress, Prefix, RIR, Role, VLAN, VLANGroup, VRF
|
from .models import Aggregate, IPAddress, Prefix, RIR, Role, VLAN, VLANGroup, VRF
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
from netaddr import IPNetwork
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from netaddr import IPNetwork
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
from rest_framework.test import APITestCase
|
from rest_framework.test import APITestCase
|
||||||
|
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import netaddr
|
import netaddr
|
||||||
|
|
||||||
|
from django.core.exceptions import ValidationError
|
||||||
from django.test import TestCase, override_settings
|
from django.test import TestCase, override_settings
|
||||||
|
|
||||||
from ipam.models import IPAddress, Prefix, VRF
|
from ipam.models import IPAddress, Prefix, VRF
|
||||||
from django.core.exceptions import ValidationError
|
|
||||||
|
|
||||||
|
|
||||||
class TestPrefix(TestCase):
|
class TestPrefix(TestCase):
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
|
|
||||||
from . import views
|
from . import views
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django_tables2 import RequestConfig
|
from django_tables2 import RequestConfig
|
||||||
import netaddr
|
import netaddr
|
||||||
|
|
||||||
@ -13,7 +15,6 @@ from utilities.paginator import EnhancedPaginator
|
|||||||
from utilities.views import (
|
from utilities.views import (
|
||||||
BulkAddView, BulkDeleteView, BulkEditView, BulkImportView, ObjectDeleteView, ObjectEditView, ObjectListView,
|
BulkAddView, BulkDeleteView, BulkEditView, BulkImportView, ObjectDeleteView, ObjectEditView, ObjectListView,
|
||||||
)
|
)
|
||||||
|
|
||||||
from . import filters, forms, tables
|
from . import filters, forms, tables
|
||||||
from .models import (
|
from .models import (
|
||||||
Aggregate, IPAddress, PREFIX_STATUS_ACTIVE, PREFIX_STATUS_DEPRECATED, PREFIX_STATUS_RESERVED, Prefix, RIR, Role,
|
Aggregate, IPAddress, PREFIX_STATUS_ACTIVE, PREFIX_STATUS_DEPRECATED, PREFIX_STATUS_RESERVED, Prefix, RIR, Role,
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
|
|
||||||
from utilities.forms import BootstrapMixin
|
from utilities.forms import BootstrapMixin
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from rest_framework_swagger.views import get_swagger_view
|
from rest_framework_swagger.views import get_swagger_view
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
@ -195,7 +196,7 @@ class SearchView(View):
|
|||||||
results.append({
|
results.append({
|
||||||
'name': queryset.model._meta.verbose_name_plural,
|
'name': queryset.model._meta.verbose_name_plural,
|
||||||
'table': table,
|
'table': table,
|
||||||
'url': u'{}?q={}'.format(reverse(url), form.cleaned_data['q'])
|
'url': '{}?q={}'.format(reverse(url), form.cleaned_data['q'])
|
||||||
})
|
})
|
||||||
|
|
||||||
return render(request, 'search.html', {
|
return render(request, 'search.html', {
|
||||||
@ -209,7 +210,7 @@ class APIRootView(APIView):
|
|||||||
exclude_from_schema = True
|
exclude_from_schema = True
|
||||||
|
|
||||||
def get_view_name(self):
|
def get_view_name(self):
|
||||||
return u"API Root"
|
return "API Root"
|
||||||
|
|
||||||
def get(self, request, format=None):
|
def get(self, request, format=None):
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ import os
|
|||||||
|
|
||||||
from django.core.wsgi import get_wsgi_application
|
from django.core.wsgi import get_wsgi_application
|
||||||
|
|
||||||
|
|
||||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "netbox.settings")
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "netbox.settings")
|
||||||
|
|
||||||
application = get_wsgi_application()
|
application = get_wsgi_application()
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.contrib import admin, messages
|
from django.contrib import admin, messages
|
||||||
from django.shortcuts import redirect, render
|
from django.shortcuts import redirect, render
|
||||||
|
|
||||||
@ -34,7 +36,7 @@ class UserKeyAdmin(admin.ModelAdmin):
|
|||||||
try:
|
try:
|
||||||
my_userkey = UserKey.objects.get(user=request.user)
|
my_userkey = UserKey.objects.get(user=request.user)
|
||||||
except UserKey.DoesNotExist:
|
except UserKey.DoesNotExist:
|
||||||
messages.error(request, u"You do not have an active User Key.")
|
messages.error(request, "You do not have an active User Key.")
|
||||||
return redirect('admin:secrets_userkey_changelist')
|
return redirect('admin:secrets_userkey_changelist')
|
||||||
|
|
||||||
if 'activate' in request.POST:
|
if 'activate' in request.POST:
|
||||||
@ -46,7 +48,7 @@ class UserKeyAdmin(admin.ModelAdmin):
|
|||||||
uk.activate(master_key)
|
uk.activate(master_key)
|
||||||
return redirect('admin:secrets_userkey_changelist')
|
return redirect('admin:secrets_userkey_changelist')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
messages.error(request, u"Invalid private key provided. Unable to retrieve master key.")
|
messages.error(request, "Invalid private key provided. Unable to retrieve master key.")
|
||||||
else:
|
else:
|
||||||
form = ActivateUserKeyForm(initial={'_selected_action': request.POST.getlist(admin.ACTION_CHECKBOX_NAME)})
|
form = ActivateUserKeyForm(initial={'_selected_action': request.POST.getlist(admin.ACTION_CHECKBOX_NAME)})
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from rest_framework.validators import UniqueTogetherValidator
|
from rest_framework.validators import UniqueTogetherValidator
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from rest_framework import routers
|
from rest_framework import routers
|
||||||
|
|
||||||
from . import views
|
from . import views
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
import base64
|
import base64
|
||||||
|
|
||||||
from Crypto.PublicKey import RSA
|
from Crypto.PublicKey import RSA
|
||||||
|
|
||||||
from django.http import HttpResponseBadRequest
|
|
||||||
|
|
||||||
from rest_framework.exceptions import ValidationError
|
from rest_framework.exceptions import ValidationError
|
||||||
from rest_framework.permissions import IsAuthenticated
|
from rest_framework.permissions import IsAuthenticated
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.viewsets import ModelViewSet, ViewSet
|
from rest_framework.viewsets import ModelViewSet, ViewSet
|
||||||
|
|
||||||
|
from django.http import HttpResponseBadRequest
|
||||||
|
|
||||||
from secrets import filters
|
from secrets import filters
|
||||||
from secrets.exceptions import InvalidKey
|
from secrets.exceptions import InvalidKey
|
||||||
from secrets.models import Secret, SecretRole, SessionKey, UserKey
|
from secrets.models import Secret, SecretRole, SessionKey, UserKey
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
|
|
||||||
@ -14,10 +16,10 @@ def userkey_required():
|
|||||||
try:
|
try:
|
||||||
uk = UserKey.objects.get(user=request.user)
|
uk = UserKey.objects.get(user=request.user)
|
||||||
except UserKey.DoesNotExist:
|
except UserKey.DoesNotExist:
|
||||||
messages.warning(request, u"This operation requires an active user key, but you don't have one.")
|
messages.warning(request, "This operation requires an active user key, but you don't have one.")
|
||||||
return redirect('user:userkey')
|
return redirect('user:userkey')
|
||||||
if not uk.is_active():
|
if not uk.is_active():
|
||||||
messages.warning(request, u"This operation is not available. Your user key has not been activated.")
|
messages.warning(request, "This operation is not available. Your user key has not been activated.")
|
||||||
return redirect('user:userkey')
|
return redirect('user:userkey')
|
||||||
return view(request, *args, **kwargs)
|
return view(request, *args, **kwargs)
|
||||||
return wrapped_view
|
return wrapped_view
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
|
||||||
class InvalidKey(Exception):
|
class InvalidKey(Exception):
|
||||||
"""
|
"""
|
||||||
Raised when a provided key is invalid.
|
Raised when a provided key is invalid.
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import django_filters
|
import django_filters
|
||||||
|
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from Crypto.Cipher import PKCS1_OAEP
|
from Crypto.Cipher import PKCS1_OAEP
|
||||||
from Crypto.PublicKey import RSA
|
from Crypto.PublicKey import RSA
|
||||||
|
|
||||||
@ -6,7 +8,6 @@ from django.db.models import Count
|
|||||||
|
|
||||||
from dcim.models import Device
|
from dcim.models import Device
|
||||||
from utilities.forms import BootstrapMixin, BulkEditForm, BulkImportForm, CSVDataField, FilterChoiceField, SlugField
|
from utilities.forms import BootstrapMixin, BulkEditForm, BulkImportForm, CSVDataField, FilterChoiceField, SlugField
|
||||||
|
|
||||||
from .models import Secret, SecretRole, UserKey
|
from .models import Secret, SecretRole, UserKey
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.contrib.auth.hashers import PBKDF2PasswordHasher
|
from django.contrib.auth.hashers import PBKDF2PasswordHasher
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from Crypto.Cipher import AES, PKCS1_OAEP, XOR
|
from Crypto.Cipher import AES, PKCS1_OAEP, XOR
|
||||||
from Crypto.PublicKey import RSA
|
from Crypto.PublicKey import RSA
|
||||||
|
|
||||||
@ -12,7 +14,6 @@ from django.utils.encoding import force_bytes, python_2_unicode_compatible
|
|||||||
|
|
||||||
from dcim.models import Device
|
from dcim.models import Device
|
||||||
from utilities.models import CreatedUpdatedModel
|
from utilities.models import CreatedUpdatedModel
|
||||||
|
|
||||||
from .exceptions import InvalidKey
|
from .exceptions import InvalidKey
|
||||||
from .hashers import SecretValidationHasher
|
from .hashers import SecretValidationHasher
|
||||||
|
|
||||||
@ -301,8 +302,8 @@ class Secret(CreatedUpdatedModel):
|
|||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
if self.role and self.device:
|
if self.role and self.device:
|
||||||
return u'{} for {}'.format(self.role, self.device)
|
return '{} for {}'.format(self.role, self.device)
|
||||||
return u'Secret'
|
return 'Secret'
|
||||||
|
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return reverse('secrets:secret', args=[self.pk])
|
return reverse('secrets:secret', args=[self.pk])
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import django_tables2 as tables
|
import django_tables2 as tables
|
||||||
from django_tables2.utils import Accessor
|
|
||||||
|
|
||||||
from utilities.tables import BaseTable, SearchTable, ToggleColumn
|
from utilities.tables import BaseTable, SearchTable, ToggleColumn
|
||||||
|
|
||||||
@ -22,8 +23,9 @@ class SecretRoleTable(BaseTable):
|
|||||||
name = tables.LinkColumn(verbose_name='Name')
|
name = tables.LinkColumn(verbose_name='Name')
|
||||||
secret_count = tables.Column(verbose_name='Secrets')
|
secret_count = tables.Column(verbose_name='Secrets')
|
||||||
slug = tables.Column(verbose_name='Slug')
|
slug = tables.Column(verbose_name='Slug')
|
||||||
actions = tables.TemplateColumn(template_code=SECRETROLE_ACTIONS, attrs={'td': {'class': 'text-right'}},
|
actions = tables.TemplateColumn(
|
||||||
verbose_name='')
|
template_code=SECRETROLE_ACTIONS, attrs={'td': {'class': 'text-right'}}, verbose_name=''
|
||||||
|
)
|
||||||
|
|
||||||
class Meta(BaseTable.Meta):
|
class Meta(BaseTable.Meta):
|
||||||
model = SecretRole
|
model = SecretRole
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django import template
|
from django import template
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
import base64
|
import base64
|
||||||
|
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
from rest_framework.test import APITestCase
|
from rest_framework.test import APITestCase
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from Crypto.PublicKey import RSA
|
from Crypto.PublicKey import RSA
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
|
|
||||||
from . import views
|
from . import views
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
import base64
|
import base64
|
||||||
|
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
@ -12,7 +13,6 @@ from django.views.generic import View
|
|||||||
|
|
||||||
from dcim.models import Device
|
from dcim.models import Device
|
||||||
from utilities.views import BulkDeleteView, BulkEditView, ObjectDeleteView, ObjectEditView, ObjectListView
|
from utilities.views import BulkDeleteView, BulkEditView, ObjectDeleteView, ObjectEditView, ObjectListView
|
||||||
|
|
||||||
from . import filters, forms, tables
|
from . import filters, forms, tables
|
||||||
from .decorators import userkey_required
|
from .decorators import userkey_required
|
||||||
from .models import SecretRole, Secret, SessionKey
|
from .models import SecretRole, Secret, SessionKey
|
||||||
@ -110,7 +110,7 @@ def secret_add(request, pk):
|
|||||||
secret.plaintext = str(form.cleaned_data['plaintext'])
|
secret.plaintext = str(form.cleaned_data['plaintext'])
|
||||||
secret.encrypt(master_key)
|
secret.encrypt(master_key)
|
||||||
secret.save()
|
secret.save()
|
||||||
messages.success(request, u"Added new secret: {}.".format(secret))
|
messages.success(request, "Added new secret: {}.".format(secret))
|
||||||
if '_addanother' in request.POST:
|
if '_addanother' in request.POST:
|
||||||
return redirect('dcim:device_addsecret', pk=device.pk)
|
return redirect('dcim:device_addsecret', pk=device.pk)
|
||||||
else:
|
else:
|
||||||
@ -154,7 +154,7 @@ def secret_edit(request, pk):
|
|||||||
secret.plaintext = str(form.cleaned_data['plaintext'])
|
secret.plaintext = str(form.cleaned_data['plaintext'])
|
||||||
secret.encrypt(master_key)
|
secret.encrypt(master_key)
|
||||||
secret.save()
|
secret.save()
|
||||||
messages.success(request, u"Modified secret {}.".format(secret))
|
messages.success(request, "Modified secret {}.".format(secret))
|
||||||
return redirect('secrets:secret', pk=secret.pk)
|
return redirect('secrets:secret', pk=secret.pk)
|
||||||
else:
|
else:
|
||||||
form.add_error(None, "Invalid session key. Unable to encrypt secret data.")
|
form.add_error(None, "Invalid session key. Unable to encrypt secret data.")
|
||||||
@ -166,7 +166,7 @@ def secret_edit(request, pk):
|
|||||||
# If no new plaintext was specified, a session key is not needed.
|
# If no new plaintext was specified, a session key is not needed.
|
||||||
else:
|
else:
|
||||||
secret = form.save()
|
secret = form.save()
|
||||||
messages.success(request, u"Modified secret {}.".format(secret))
|
messages.success(request, "Modified secret {}.".format(secret))
|
||||||
return redirect('secrets:secret', pk=secret.pk)
|
return redirect('secrets:secret', pk=secret.pk)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@ -220,7 +220,7 @@ def secret_import(request):
|
|||||||
new_secrets.append(secret)
|
new_secrets.append(secret)
|
||||||
|
|
||||||
table = tables.SecretTable(new_secrets)
|
table = tables.SecretTable(new_secrets)
|
||||||
messages.success(request, u"Imported {} new secrets.".format(len(new_secrets)))
|
messages.success(request, "Imported {} new secrets.".format(len(new_secrets)))
|
||||||
|
|
||||||
return render(request, 'import_success.html', {
|
return render(request, 'import_success.html', {
|
||||||
'table': table,
|
'table': table,
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
from extras.api.customfields import CustomFieldModelSerializer
|
from extras.api.customfields import CustomFieldModelSerializer
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from rest_framework import routers
|
from rest_framework import routers
|
||||||
|
|
||||||
from . import views
|
from . import views
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from rest_framework.viewsets import ModelViewSet
|
from rest_framework.viewsets import ModelViewSet
|
||||||
|
|
||||||
|
from extras.api.views import CustomFieldModelViewSet
|
||||||
from tenancy.models import Tenant, TenantGroup
|
from tenancy.models import Tenant, TenantGroup
|
||||||
from tenancy.filters import TenantFilter
|
from tenancy.filters import TenantFilter
|
||||||
|
|
||||||
from extras.api.views import CustomFieldModelViewSet
|
|
||||||
from utilities.api import WritableSerializerMixin
|
from utilities.api import WritableSerializerMixin
|
||||||
from . import serializers
|
from . import serializers
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.apps import AppConfig
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import django_filters
|
import django_filters
|
||||||
|
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.db.models import Count
|
from django.db.models import Count
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.contrib.contenttypes.fields import GenericRelation
|
from django.contrib.contenttypes.fields import GenericRelation
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import django_tables2 as tables
|
import django_tables2 as tables
|
||||||
from django_tables2.utils import Accessor
|
|
||||||
|
|
||||||
from utilities.tables import BaseTable, SearchTable, ToggleColumn
|
from utilities.tables import BaseTable, SearchTable, ToggleColumn
|
||||||
|
|
||||||
@ -22,8 +23,9 @@ class TenantGroupTable(BaseTable):
|
|||||||
name = tables.LinkColumn(verbose_name='Name')
|
name = tables.LinkColumn(verbose_name='Name')
|
||||||
tenant_count = tables.Column(verbose_name='Tenants')
|
tenant_count = tables.Column(verbose_name='Tenants')
|
||||||
slug = tables.Column(verbose_name='Slug')
|
slug = tables.Column(verbose_name='Slug')
|
||||||
actions = tables.TemplateColumn(template_code=TENANTGROUP_ACTIONS, attrs={'td': {'class': 'text-right'}},
|
actions = tables.TemplateColumn(
|
||||||
verbose_name='')
|
template_code=TENANTGROUP_ACTIONS, attrs={'td': {'class': 'text-right'}}, verbose_name=''
|
||||||
|
)
|
||||||
|
|
||||||
class Meta(BaseTable.Meta):
|
class Meta(BaseTable.Meta):
|
||||||
model = TenantGroup
|
model = TenantGroup
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
from rest_framework.test import APITestCase
|
from rest_framework.test import APITestCase
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
|
|
||||||
from . import views
|
from . import views
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.contrib.auth.mixins import PermissionRequiredMixin
|
from django.contrib.auth.mixins import PermissionRequiredMixin
|
||||||
from django.db.models import Count, Q
|
from django.db.models import Count, Q
|
||||||
from django.shortcuts import get_object_or_404, render
|
from django.shortcuts import get_object_or_404, render
|
||||||
@ -10,7 +12,6 @@ from ipam.models import IPAddress, Prefix, VLAN, VRF
|
|||||||
from utilities.views import (
|
from utilities.views import (
|
||||||
BulkDeleteView, BulkEditView, BulkImportView, ObjectDeleteView, ObjectEditView, ObjectListView,
|
BulkDeleteView, BulkEditView, BulkImportView, ObjectDeleteView, ObjectEditView, ObjectListView,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .models import Tenant, TenantGroup
|
from .models import Tenant, TenantGroup
|
||||||
from . import filters, forms, tables
|
from . import filters, forms, tables
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.contrib.auth.forms import AuthenticationForm, PasswordChangeForm as DjangoPasswordChangeForm
|
from django.contrib.auth.forms import AuthenticationForm, PasswordChangeForm as DjangoPasswordChangeForm
|
||||||
from django import forms
|
from django import forms
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
import binascii
|
import binascii
|
||||||
import os
|
import os
|
||||||
|
|
||||||
@ -26,7 +27,7 @@ class Token(models.Model):
|
|||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
# Only display the last 24 bits of the token to avoid accidental exposure.
|
# Only display the last 24 bits of the token to avoid accidental exposure.
|
||||||
return u"{} ({})".format(self.key[-6:], self.user)
|
return "{} ({})".format(self.key[-6:], self.user)
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
if not self.key:
|
if not self.key:
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
|
|
||||||
from . import views
|
from . import views
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.contrib.auth import login as auth_login, logout as auth_logout, update_session_auth_hash
|
from django.contrib.auth import login as auth_login, logout as auth_logout, update_session_auth_hash
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
@ -41,7 +43,7 @@ class LoginView(View):
|
|||||||
|
|
||||||
# Authenticate user
|
# Authenticate user
|
||||||
auth_login(request, form.get_user())
|
auth_login(request, form.get_user())
|
||||||
messages.info(request, u"Logged in as {}.".format(request.user))
|
messages.info(request, "Logged in as {}.".format(request.user))
|
||||||
|
|
||||||
return HttpResponseRedirect(redirect_to)
|
return HttpResponseRedirect(redirect_to)
|
||||||
|
|
||||||
@ -54,7 +56,7 @@ class LogoutView(View):
|
|||||||
|
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
auth_logout(request)
|
auth_logout(request)
|
||||||
messages.info(request, u"You have logged out.")
|
messages.info(request, "You have logged out.")
|
||||||
|
|
||||||
return HttpResponseRedirect(reverse('home'))
|
return HttpResponseRedirect(reverse('home'))
|
||||||
|
|
||||||
@ -91,7 +93,7 @@ class ChangePasswordView(View):
|
|||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
form.save()
|
form.save()
|
||||||
update_session_auth_hash(request, form.user)
|
update_session_auth_hash(request, form.user)
|
||||||
messages.success(request, u"Your password has been changed successfully.")
|
messages.success(request, "Your password has been changed successfully.")
|
||||||
return redirect('user:profile')
|
return redirect('user:profile')
|
||||||
|
|
||||||
return render(request, self.template_name, {
|
return render(request, self.template_name, {
|
||||||
@ -143,7 +145,7 @@ class UserKeyEditView(View):
|
|||||||
uk = form.save(commit=False)
|
uk = form.save(commit=False)
|
||||||
uk.user = request.user
|
uk.user = request.user
|
||||||
uk.save()
|
uk.save()
|
||||||
messages.success(request, u"Your user key has been saved.")
|
messages.success(request, "Your user key has been saved.")
|
||||||
return redirect('user:userkey')
|
return redirect('user:userkey')
|
||||||
|
|
||||||
return render(request, self.template_name, {
|
return render(request, self.template_name, {
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.conf import settings as django_settings
|
from django.conf import settings as django_settings
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.utils.html import escape
|
from django.utils.html import escape
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
@ -14,12 +16,12 @@ def handle_protectederror(obj, request, e):
|
|||||||
|
|
||||||
# Grammar for single versus multiple triggering objects
|
# Grammar for single versus multiple triggering objects
|
||||||
if type(obj) in (list, tuple):
|
if type(obj) in (list, tuple):
|
||||||
err_message = u"Unable to delete the requested {}. The following dependent {} were found: ".format(
|
err_message = "Unable to delete the requested {}. The following dependent {} were found: ".format(
|
||||||
obj[0]._meta.verbose_name_plural,
|
obj[0]._meta.verbose_name_plural,
|
||||||
dep_class,
|
dep_class,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
err_message = u"Unable to delete {} {}. The following dependent {} were found: ".format(
|
err_message = "Unable to delete {} {}. The following dependent {} were found: ".format(
|
||||||
obj._meta.verbose_name,
|
obj._meta.verbose_name,
|
||||||
obj,
|
obj,
|
||||||
dep_class,
|
dep_class,
|
||||||
@ -29,9 +31,9 @@ def handle_protectederror(obj, request, e):
|
|||||||
dependent_objects = []
|
dependent_objects = []
|
||||||
for obj in e.protected_objects:
|
for obj in e.protected_objects:
|
||||||
if hasattr(obj, 'get_absolute_url'):
|
if hasattr(obj, 'get_absolute_url'):
|
||||||
dependent_objects.append(u'<a href="{}">{}</a>'.format(obj.get_absolute_url(), escape(obj)))
|
dependent_objects.append('<a href="{}">{}</a>'.format(obj.get_absolute_url(), escape(obj)))
|
||||||
else:
|
else:
|
||||||
dependent_objects.append(str(obj))
|
dependent_objects.append(str(obj))
|
||||||
err_message += u', '.join(dependent_objects)
|
err_message += ', '.join(dependent_objects)
|
||||||
|
|
||||||
messages.error(request, mark_safe(err_message))
|
messages.error(request, mark_safe(err_message))
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.core.validators import RegexValidator
|
from django.core.validators import RegexValidator
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import django_filters
|
import django_filters
|
||||||
import itertools
|
import itertools
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
import csv
|
import csv
|
||||||
import itertools
|
import itertools
|
||||||
import re
|
import re
|
||||||
@ -373,7 +374,7 @@ class FilterChoiceFieldMixin(object):
|
|||||||
def label_from_instance(self, obj):
|
def label_from_instance(self, obj):
|
||||||
label = super(FilterChoiceFieldMixin, self).label_from_instance(obj)
|
label = super(FilterChoiceFieldMixin, self).label_from_instance(obj)
|
||||||
if hasattr(obj, 'filter_count'):
|
if hasattr(obj, 'filter_count'):
|
||||||
return u'{} ({})'.format(label, obj.filter_count)
|
return '{} ({})'.format(label, obj.filter_count)
|
||||||
return label
|
return label
|
||||||
|
|
||||||
def _get_choices(self):
|
def _get_choices(self):
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user