Skip to content

Commit

Permalink
Merge v2.5.11
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremystretch committed Apr 29, 2019
2 parents 2c730b0 + d5dcb77 commit 37c2c4b
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 43 deletions.
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,28 @@ functionality provided by the front end UI.

---

2.5.11 (2019-04-29)

## Notes

This release upgrades the Django framework to version 2.2.

## Enhancements

* [#2986](https://github.com/digitalocean/netbox/issues/2986) - Improve natural ordering of device components
* [#3023](https://github.com/digitalocean/netbox/issues/3023) - Add support for filtering cables by connected device
* [#3070](https://github.com/digitalocean/netbox/issues/3070) - Add decommissioning status for devices

## Bug Fixes

* [#2621](https://github.com/digitalocean/netbox/issues/2621) - Upgrade Django requirement to 2.2 to fix object deletion issue in the changelog middleware
* [#3072](https://github.com/digitalocean/netbox/issues/3072) - Preserve multiselect filter values when updating per-page count for list views
* [#3112](https://github.com/digitalocean/netbox/issues/3112) - Fix ordering of interface connections list by termination B name/device
* [#3116](https://github.com/digitalocean/netbox/issues/3116) - Fix `tagged_items` count in tags API endpoint
* [#3118](https://github.com/digitalocean/netbox/issues/3118) - Disable `last_login` update on login when maintenance mode is enabled

---

v2.5.10 (2019-04-08)

## Enhancements
Expand Down
3 changes: 3 additions & 0 deletions netbox/dcim/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,15 @@
DEVICE_STATUS_STAGED = 3
DEVICE_STATUS_FAILED = 4
DEVICE_STATUS_INVENTORY = 5
DEVICE_STATUS_DECOMMISSIONING = 6
DEVICE_STATUS_CHOICES = [
[DEVICE_STATUS_ACTIVE, 'Active'],
[DEVICE_STATUS_OFFLINE, 'Offline'],
[DEVICE_STATUS_PLANNED, 'Planned'],
[DEVICE_STATUS_STAGED, 'Staged'],
[DEVICE_STATUS_FAILED, 'Failed'],
[DEVICE_STATUS_INVENTORY, 'Inventory'],
[DEVICE_STATUS_DECOMMISSIONING, 'Decommissioning'],
]

# Site statuses
Expand All @@ -345,6 +347,7 @@
3: 'primary',
4: 'danger',
5: 'default',
6: 'warning',
}

# Console/power/interface connection statuses
Expand Down
20 changes: 20 additions & 0 deletions netbox/dcim/filters.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import django_filters
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ObjectDoesNotExist
from django.db.models import Q
from netaddr import EUI
from netaddr.core import AddrFormatError
Expand Down Expand Up @@ -969,6 +971,14 @@ class CableFilter(django_filters.FilterSet):
color = django_filters.MultipleChoiceFilter(
choices=COLOR_CHOICES
)
device = django_filters.CharFilter(
method='filter_connected_device',
field_name='name'
)
device_id = django_filters.CharFilter(
method='filter_connected_device',
field_name='pk'
)

class Meta:
model = Cable
Expand All @@ -979,6 +989,16 @@ def search(self, queryset, name, value):
return queryset
return queryset.filter(label__icontains=value)

def filter_connected_device(self, queryset, name, value):
if not value.strip():
return queryset
try:
device = Device.objects.get(**{name: value})
except ObjectDoesNotExist:
return queryset.none()
cable_pks = device.get_cables(pk_list=True)
return queryset.filter(pk__in=cable_pks)


class ConsoleConnectionFilter(django_filters.FilterSet):
site = django_filters.CharFilter(
Expand Down
4 changes: 4 additions & 0 deletions netbox/dcim/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3003,6 +3003,10 @@ class CableFilterForm(BootstrapMixin, forms.Form):
required=False,
widget=ColorSelect()
)
device = forms.CharField(
required=False,
label='Device name'
)


#
Expand Down
16 changes: 0 additions & 16 deletions netbox/dcim/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,6 @@
VC_RE = r"COALESCE(CAST(SUBSTRING({} FROM '^.*\.(\d{{1,9}})$') AS integer), 0)"


class DeviceComponentManager(Manager):

def get_queryset(self):

queryset = super().get_queryset()
table_name = self.model._meta.db_table
sql = r"CONCAT(REGEXP_REPLACE({}.name, '\d+$', ''), LPAD(SUBSTRING({}.name FROM '\d+$'), 8, '0'))"

# Pad any trailing digits to effect natural sorting
return queryset.extra(
select={
'name_padded': sql.format(table_name, table_name),
}
).order_by('name_padded', 'pk')


class InterfaceQuerySet(QuerySet):

def connectable(self):
Expand Down
45 changes: 30 additions & 15 deletions netbox/dcim/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from .constants import *
from .exceptions import LoopDetected
from .fields import ASNField, MACAddressField
from .managers import DeviceComponentManager, InterfaceManager
from .managers import InterfaceManager


class ComponentTemplateModel(models.Model):
Expand Down Expand Up @@ -982,7 +982,7 @@ class ConsolePortTemplate(ComponentTemplateModel):
max_length=50
)

objects = DeviceComponentManager()
objects = NaturalOrderingManager()

class Meta:
ordering = ['device_type', 'name']
Expand All @@ -1005,7 +1005,7 @@ class ConsoleServerPortTemplate(ComponentTemplateModel):
max_length=50
)

objects = DeviceComponentManager()
objects = NaturalOrderingManager()

class Meta:
ordering = ['device_type', 'name']
Expand Down Expand Up @@ -1040,7 +1040,7 @@ class PowerPortTemplate(ComponentTemplateModel):
help_text="Allocated current draw (watts)"
)

objects = DeviceComponentManager()
objects = NaturalOrderingManager()

class Meta:
ordering = ['device_type', 'name']
Expand Down Expand Up @@ -1076,7 +1076,7 @@ class PowerOutletTemplate(ComponentTemplateModel):
help_text="Phase (for three-phase feeds)"
)

objects = DeviceComponentManager()
objects = NaturalOrderingManager()

class Meta:
ordering = ['device_type', 'name']
Expand Down Expand Up @@ -1166,7 +1166,7 @@ class FrontPortTemplate(ComponentTemplateModel):
validators=[MinValueValidator(1), MaxValueValidator(64)]
)

objects = DeviceComponentManager()
objects = NaturalOrderingManager()

class Meta:
ordering = ['device_type', 'name']
Expand Down Expand Up @@ -1215,7 +1215,7 @@ class RearPortTemplate(ComponentTemplateModel):
validators=[MinValueValidator(1), MaxValueValidator(64)]
)

objects = DeviceComponentManager()
objects = NaturalOrderingManager()

class Meta:
ordering = ['device_type', 'name']
Expand All @@ -1238,7 +1238,7 @@ class DeviceBayTemplate(ComponentTemplateModel):
max_length=50
)

objects = DeviceComponentManager()
objects = NaturalOrderingManager()

class Meta:
ordering = ['device_type', 'name']
Expand Down Expand Up @@ -1731,6 +1731,21 @@ def vc_interfaces(self):
filter |= Q(device__virtual_chassis=self.virtual_chassis, mgmt_only=False)
return Interface.objects.filter(filter)

def get_cables(self, pk_list=False):
"""
Return a QuerySet or PK list matching all Cables connected to a component of this Device.
"""
cable_pks = []
for component_model in [
ConsolePort, ConsoleServerPort, PowerPort, PowerOutlet, Interface, FrontPort, RearPort
]:
cable_pks += component_model.objects.filter(
device=self, cable__isnull=False
).values_list('cable', flat=True)
if pk_list:
return cable_pks
return Cable.objects.filter(pk__in=cable_pks)

def get_children(self):
"""
Return the set of child Devices installed in DeviceBays within this Device.
Expand Down Expand Up @@ -1769,7 +1784,7 @@ class ConsolePort(CableTermination, ComponentModel):
blank=True
)

objects = DeviceComponentManager()
objects = NaturalOrderingManager()
tags = TaggableManager(through=TaggedItem)

csv_headers = ['device', 'name', 'description']
Expand Down Expand Up @@ -1813,7 +1828,7 @@ class ConsoleServerPort(CableTermination, ComponentModel):
blank=True
)

objects = DeviceComponentManager()
objects = NaturalOrderingManager()
tags = TaggableManager(through=TaggedItem)

csv_headers = ['device', 'name', 'description']
Expand Down Expand Up @@ -1882,7 +1897,7 @@ class PowerPort(CableTermination, ComponentModel):
blank=True
)

objects = DeviceComponentManager()
objects = NaturalOrderingManager()
tags = TaggableManager(through=TaggedItem)

csv_headers = ['device', 'name', 'maximum_draw', 'allocated_draw', 'description']
Expand Down Expand Up @@ -1998,7 +2013,7 @@ class PowerOutlet(CableTermination, ComponentModel):
blank=True
)

objects = DeviceComponentManager()
objects = NaturalOrderingManager()
tags = TaggableManager(through=TaggedItem)

csv_headers = ['device', 'name', 'power_port', 'feed_leg', 'description']
Expand Down Expand Up @@ -2338,7 +2353,7 @@ class FrontPort(CableTermination, ComponentModel):
validators=[MinValueValidator(1), MaxValueValidator(64)]
)

objects = DeviceComponentManager()
objects = NaturalOrderingManager()
tags = TaggableManager(through=TaggedItem)

csv_headers = ['device', 'name', 'type', 'rear_port', 'rear_port_position', 'description']
Expand Down Expand Up @@ -2400,7 +2415,7 @@ class RearPort(CableTermination, ComponentModel):
validators=[MinValueValidator(1), MaxValueValidator(64)]
)

objects = DeviceComponentManager()
objects = NaturalOrderingManager()
tags = TaggableManager(through=TaggedItem)

csv_headers = ['device', 'name', 'type', 'positions', 'description']
Expand Down Expand Up @@ -2447,7 +2462,7 @@ class DeviceBay(ComponentModel):
null=True
)

objects = DeviceComponentManager()
objects = NaturalOrderingManager()
tags = TaggableManager(through=TaggedItem)

csv_headers = ['device', 'name', 'installed_device', 'description']
Expand Down
10 changes: 5 additions & 5 deletions netbox/dcim/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,18 +743,18 @@ class InterfaceConnectionTable(BaseTable):
)
device_b = tables.LinkColumn(
viewname='dcim:device',
accessor=Accessor('connected_endpoint.device'),
args=[Accessor('connected_endpoint.device.pk')],
accessor=Accessor('_connected_interface.device'),
args=[Accessor('_connected_interface.device.pk')],
verbose_name='Device B'
)
interface_b = tables.LinkColumn(
viewname='dcim:interface',
accessor=Accessor('connected_endpoint.name'),
args=[Accessor('connected_endpoint.pk')],
accessor=Accessor('_connected_interface'),
args=[Accessor('_connected_interface.pk')],
verbose_name='Interface B'
)
description_b = tables.Column(
accessor=Accessor('connected_endpoint.description'),
accessor=Accessor('_connected_interface.description'),
verbose_name='Description'
)

Expand Down
4 changes: 3 additions & 1 deletion netbox/extras/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ def render(self, request, pk):
#

class TagViewSet(ModelViewSet):
queryset = Tag.objects.annotate(tagged_items=Count('extras_taggeditem_items'))
queryset = Tag.objects.annotate(
tagged_items=Count('taggit_taggeditem_items', distinct=True)
)
serializer_class = serializers.TagSerializer
filterset_class = filters.TagFilter

Expand Down
2 changes: 1 addition & 1 deletion netbox/extras/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

class TagListView(ObjectListView):
queryset = Tag.objects.annotate(
items=Count('extras_taggeditem_items')
items=Count('taggit_taggeditem_items', distinct=True)
).order_by(
'name'
)
Expand Down
6 changes: 4 additions & 2 deletions netbox/templates/inc/paginator.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
</ul>
</nav>
<form method="get">
{% for k, v in request.GET.items %}
{% for k, v_list in request.GET.lists %}
{% if k != 'per_page' %}
<input type="hidden" name="{{ k }}" value="{{ v }}" />
{% for v in v_list %}
<input type="hidden" name="{{ k }}" value="{{ v }}" />
{% endfor %}
{% endif %}
{% endfor %}
<select name="per_page" id="per_page">
Expand Down
4 changes: 2 additions & 2 deletions netbox/templates/ipam/vlan.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ <h1>{% block title %}VLAN {{ vlan.display_name }}{% endblock %}</h1>

{% block content %}
<div class="row">
<div class="col-md-6">
<div class="col-md-4">
<div class="panel panel-default">
<div class="panel-heading">
<strong>VLAN</strong>
Expand Down Expand Up @@ -142,7 +142,7 @@ <h1>{% block title %}VLAN {{ vlan.display_name }}{% endblock %}</h1>
{% include 'inc/custom_fields_panel.html' with obj=vlan %}
{% include 'extras/inc/tags_panel.html' with tags=vlan.tags.all url='ipam:vlan_list' %}
</div>
<div class="col-md-6">
<div class="col-md-8">
<div class="panel panel-default">
<div class="panel-heading">
<strong>Prefixes</strong>
Expand Down
8 changes: 8 additions & 0 deletions netbox/users/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from django.conf import settings
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.mixins import LoginRequiredMixin, PermissionRequiredMixin
from django.contrib.auth.models import update_last_login
from django.contrib.auth.signals import user_logged_in
from django.http import HttpResponseForbidden, HttpResponseRedirect
from django.shortcuts import get_object_or_404, redirect, render
from django.urls import reverse
Expand Down Expand Up @@ -43,6 +46,11 @@ def post(self, request):
if not is_safe_url(url=redirect_to, allowed_hosts=request.get_host()):
redirect_to = reverse('home')

# If maintenance mode is enabled, assume the database is read-only, and disable updating the user's
# last_login time upon authentication.
if settings.MAINTENANCE_MODE:
user_logged_in.disconnect(update_last_login, dispatch_uid='update_last_login')

# Authenticate user
auth_login(request, form.get_user())
messages.info(request, "Logged in as {}.".format(request.user))
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Django>=2.2,<2.3
django-cacheops==4.1
django-cors-headers==2.5.2
django-cors-headers==2.4.0
django-debug-toolbar==1.11
django-filter==2.1.0
django-mptt==0.9.1
Expand Down

0 comments on commit 37c2c4b

Please sign in to comment.