diff --git a/netbox/extras/api/customfields.py b/netbox/extras/api/customfields.py index fc83b33e5..5554df924 100644 --- a/netbox/extras/api/customfields.py +++ b/netbox/extras/api/customfields.py @@ -29,34 +29,47 @@ class CustomFieldsSerializer(serializers.BaseSerializer): for field_name, value in data.items(): - cf = custom_fields[field_name] + try: + cf = custom_fields[field_name] + except KeyError: + raise ValidationError( + "Invalid custom field for {} objects: {}".format(content_type, field_name) + ) - # Validate custom field name - if field_name not in custom_fields: - raise ValidationError("Invalid custom field for {} objects: {}".format(content_type, field_name)) + # Data validation + if value not in [None, '']: - # Validate boolean - if cf.type == CF_TYPE_BOOLEAN and value not in [True, False, 1, 0]: - raise ValidationError("Invalid value for boolean field {}: {}".format(field_name, value)) + # Validate boolean + if cf.type == CF_TYPE_BOOLEAN and value not in [True, False, 1, 0]: + raise ValidationError( + "Invalid value for boolean field {}: {}".format(field_name, value) + ) - # Validate date - if cf.type == CF_TYPE_DATE: - try: - datetime.strptime(value, '%Y-%m-%d') - except ValueError: - raise ValidationError("Invalid date for field {}: {}. (Required format is YYYY-MM-DD.)".format( - field_name, value - )) + # Validate date + if cf.type == CF_TYPE_DATE: + try: + datetime.strptime(value, '%Y-%m-%d') + except ValueError: + raise ValidationError( + "Invalid date for field {}: {}. (Required format is YYYY-MM-DD.)".format(field_name, value) + ) - # Validate selected choice - if cf.type == CF_TYPE_SELECT: - try: - value = int(value) - except ValueError: - raise ValidationError("{}: Choice selections must be passed as integers.".format(field_name)) - valid_choices = [c.pk for c in cf.choices.all()] - if value not in valid_choices: - raise ValidationError("Invalid choice for field {}: {}".format(field_name, value)) + # Validate selected choice + if cf.type == CF_TYPE_SELECT: + try: + value = int(value) + except ValueError: + raise ValidationError( + "{}: Choice selections must be passed as integers.".format(field_name) + ) + valid_choices = [c.pk for c in cf.choices.all()] + if value not in valid_choices: + raise ValidationError( + "Invalid choice for field {}: {}".format(field_name, value) + ) + + elif cf.required: + raise ValidationError("Required field {} cannot be empty.".format(field_name)) # Check for missing required fields missing_fields = [] diff --git a/netbox/ipam/views.py b/netbox/ipam/views.py index 89eecd352..4152cae91 100644 --- a/netbox/ipam/views.py +++ b/netbox/ipam/views.py @@ -286,11 +286,12 @@ class AggregateListView(ObjectListView): ipv4_total = 0 ipv6_total = 0 - for a in self.queryset: - if a.prefix.version == 4: - ipv4_total += a.prefix.size - elif a.prefix.version == 6: - ipv6_total += a.prefix.size / 2 ** 64 + for aggregate in self.queryset: + if aggregate.prefix.version == 6: + # Report equivalent /64s for IPv6 to keep things sane + ipv6_total += int(aggregate.prefix.size / 2 ** 64) + else: + ipv4_total += aggregate.prefix.size return { 'ipv4_total': ipv4_total, @@ -314,7 +315,7 @@ class AggregateView(View): ) child_prefixes = add_available_prefixes(aggregate.prefix, child_prefixes) - prefix_table = tables.PrefixTable(child_prefixes) + prefix_table = tables.PrefixDetailTable(child_prefixes) if request.user.has_perm('ipam.change_prefix') or request.user.has_perm('ipam.delete_prefix'): prefix_table.base_columns['pk'].visible = True diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index 13ae4c48b..437a3ea23 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -13,7 +13,7 @@ except ImportError: ) -VERSION = '2.1.5-dev' +VERSION = '2.1.6-dev' BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -228,7 +228,7 @@ REST_FRAMEWORK = { 'utilities.api.TokenAuthentication', ), 'DEFAULT_FILTER_BACKENDS': ( - 'rest_framework.filters.DjangoFilterBackend', + 'django_filters.rest_framework.DjangoFilterBackend', ), 'DEFAULT_PAGINATION_CLASS': 'utilities.api.OptionalLimitOffsetPagination', 'DEFAULT_PERMISSION_CLASSES': ( diff --git a/netbox/templates/dcim/device_lldp_neighbors.html b/netbox/templates/dcim/device_lldp_neighbors.html index a7346c5db..99c1f6465 100644 --- a/netbox/templates/dcim/device_lldp_neighbors.html +++ b/netbox/templates/dcim/device_lldp_neighbors.html @@ -53,7 +53,7 @@ $(document).ready(function() { success: function(json) { $.each(json['get_lldp_neighbors'], function(iface, neighbors) { var neighbor = neighbors[0]; - var row = $('#' + iface.replace(/(\/)/g, "\\$1")); + var row = $('#' + iface.split(".")[0].replace(/(\/)/g, "\\$1")); var configured_device = row.children('td.configured_device').attr('data'); var configured_interface = row.children('td.configured_interface').attr('data'); // Add LLDP neighbors to table @@ -62,7 +62,7 @@ $(document).ready(function() { // Apply colors to rows if (!configured_device && neighbor['hostname']) { row.addClass('info'); - } else if (configured_device == neighbor['hostname'] && configured_interface == neighbor['port']) { + } else if (configured_device == neighbor['hostname'] && configured_interface == neighbor['port'].split(".")[0]) { row.addClass('success'); } else { row.addClass('danger'); diff --git a/netbox/templates/ipam/aggregate_list.html b/netbox/templates/ipam/aggregate_list.html index fde53a790..df8e4772e 100644 --- a/netbox/templates/ipam/aggregate_list.html +++ b/netbox/templates/ipam/aggregate_list.html @@ -20,11 +20,18 @@
IPv4 total: {{ ipv4_total|intcomma }} /32s
-IPv6 total: {{ ipv6_total|intcomma }} /64s