Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #5991: Remove display_name #6352

Merged
merged 2 commits into from
May 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions docs/release-notes/version-2.12.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,18 @@

* [#5532](https://github.com/netbox-community/netbox/issues/5532) - Drop support for Python 3.6
* [#5994](https://github.com/netbox-community/netbox/issues/5994) - Drop support for `display_field` argument on ObjectVar

### REST API Changes

* dcim.Device
* Removed the `display_name` attribute (use `display` instead)
* dcim.DeviceType
* Removed the `display_name` attribute (use `display` instead)
* dcim.Rack
* Removed the `display_name` attribute (use `display` instead)
* extras.ContentType
* Removed the `display_name` attribute (use `display` instead)
* ipam.VLAN
* Removed the `display_name` attribute (use `display` instead)
* ipam.VRF
* Removed the `display_name` attribute (use `display` instead)
6 changes: 3 additions & 3 deletions netbox/dcim/api/nested_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class NestedRackSerializer(WritableNestedSerializer):

class Meta:
model = models.Rack
fields = ['id', 'url', 'display', 'name', 'display_name', 'device_count']
fields = ['id', 'url', 'display', 'name', 'device_count']


class NestedRackReservationSerializer(WritableNestedSerializer):
Expand Down Expand Up @@ -136,7 +136,7 @@ class NestedDeviceTypeSerializer(WritableNestedSerializer):

class Meta:
model = models.DeviceType
fields = ['id', 'url', 'display', 'manufacturer', 'model', 'slug', 'display_name', 'device_count']
fields = ['id', 'url', 'display', 'manufacturer', 'model', 'slug', 'device_count']


class NestedConsolePortTemplateSerializer(WritableNestedSerializer):
Expand Down Expand Up @@ -232,7 +232,7 @@ class NestedDeviceSerializer(WritableNestedSerializer):

class Meta:
model = models.Device
fields = ['id', 'url', 'display', 'name', 'display_name']
fields = ['id', 'url', 'display', 'name']


class NestedConsoleServerPortSerializer(WritableNestedSerializer):
Expand Down
29 changes: 14 additions & 15 deletions netbox/dcim/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,9 @@ class RackSerializer(PrimaryModelSerializer):
class Meta:
model = Rack
fields = [
'id', 'url', 'display', 'name', 'facility_id', 'display_name', 'site', 'location', 'tenant', 'status',
'role', 'serial', 'asset_tag', 'type', 'width', 'u_height', 'desc_units', 'outer_width', 'outer_depth',
'outer_unit', 'comments', 'tags', 'custom_fields', 'created', 'last_updated', 'device_count',
'powerfeed_count',
'id', 'url', 'display', 'name', 'facility_id', 'site', 'location', 'tenant', 'status', 'role', 'serial',
'asset_tag', 'type', 'width', 'u_height', 'desc_units', 'outer_width', 'outer_depth', 'outer_unit',
'comments', 'tags', 'custom_fields', 'created', 'last_updated', 'device_count', 'powerfeed_count',
]
# Omit the UniqueTogetherValidator that would be automatically added to validate (location, facility_id). This
# prevents facility_id from being interpreted as a required field.
Expand Down Expand Up @@ -284,9 +283,9 @@ class DeviceTypeSerializer(PrimaryModelSerializer):
class Meta:
model = DeviceType
fields = [
'id', 'url', 'display', 'manufacturer', 'model', 'slug', 'display_name', 'part_number', 'u_height',
'is_full_depth', 'subdevice_role', 'front_image', 'rear_image', 'comments', 'tags', 'custom_fields',
'created', 'last_updated', 'device_count',
'id', 'url', 'display', 'manufacturer', 'model', 'slug', 'part_number', 'u_height', 'is_full_depth',
'subdevice_role', 'front_image', 'rear_image', 'comments', 'tags', 'custom_fields', 'created',
'last_updated', 'device_count',
]


Expand Down Expand Up @@ -465,10 +464,10 @@ class DeviceSerializer(PrimaryModelSerializer):
class Meta:
model = Device
fields = [
'id', 'url', 'display', 'name', 'display_name', 'device_type', 'device_role', 'tenant', 'platform',
'serial', 'asset_tag', 'site', 'location', 'rack', 'position', 'face', 'parent_device', 'status',
'primary_ip', 'primary_ip4', 'primary_ip6', 'cluster', 'virtual_chassis', 'vc_position', 'vc_priority',
'comments', 'local_context_data', 'tags', 'custom_fields', 'created', 'last_updated',
'id', 'url', 'display', 'name', 'device_type', 'device_role', 'tenant', 'platform', 'serial', 'asset_tag',
'site', 'location', 'rack', 'position', 'face', 'parent_device', 'status', 'primary_ip', 'primary_ip4',
'primary_ip6', 'cluster', 'virtual_chassis', 'vc_position', 'vc_priority', 'comments', 'local_context_data',
'tags', 'custom_fields', 'created', 'last_updated',
]
validators = []

Expand Down Expand Up @@ -501,10 +500,10 @@ class DeviceWithConfigContextSerializer(DeviceSerializer):

class Meta(DeviceSerializer.Meta):
fields = [
'id', 'url', 'display', 'name', 'display_name', 'device_type', 'device_role', 'tenant', 'platform',
'serial', 'asset_tag', 'site', 'location', 'rack', 'position', 'face', 'parent_device', 'status',
'primary_ip', 'primary_ip4', 'primary_ip6', 'cluster', 'virtual_chassis', 'vc_position', 'vc_priority',
'comments', 'local_context_data', 'tags', 'custom_fields', 'config_context', 'created', 'last_updated',
'id', 'url', 'display', 'name', 'device_type', 'device_role', 'tenant', 'platform', 'serial', 'asset_tag',
'site', 'location', 'rack', 'position', 'face', 'parent_device', 'status', 'primary_ip', 'primary_ip4',
'primary_ip6', 'cluster', 'virtual_chassis', 'vc_position', 'vc_priority', 'comments', 'local_context_data',
'tags', 'custom_fields', 'config_context', 'created', 'last_updated',
]

@swagger_serializer_method(serializer_or_field=serializers.DictField)
Expand Down
5 changes: 3 additions & 2 deletions netbox/dcim/elevations.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ def __init__(self, rack, user=None, include_images=True, base_url=None):

@staticmethod
def _get_device_description(device):
return '{} ({}) — {} ({}U) {} {}'.format(
return '{} ({}) — {} {} ({}U) {} {}'.format(
device.name,
device.device_role,
device.device_type.display_name,
device.device_type.manufacturer.name,
device.device_type.model,
device.device_type.u_height,
device.asset_tag or '',
device.serial or ''
Expand Down
23 changes: 7 additions & 16 deletions netbox/dcim/models/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,6 @@ def delete(self, *args, **kwargs):
if self.rear_image:
self.rear_image.delete(save=False)

@property
def display_name(self):
return f'{self.manufacturer.name} {self.model}'

@property
def is_parent_device(self):
return self.subdevice_role == SubdeviceRoleChoices.ROLE_PARENT
Expand Down Expand Up @@ -622,7 +618,13 @@ class Meta:
)

def __str__(self):
return self.display_name or super().__str__()
if self.name:
return self.name
elif self.virtual_chassis:
return f'{self.virtual_chassis.name}:{self.vc_position} ({self.pk})'
elif self.device_type:
return f'{self.device_type.manufacturer} {self.device_type.model} ({self.pk})'
return super().__str__()

def get_absolute_url(self):
return reverse('dcim:device', args=[self.pk])
Expand Down Expand Up @@ -823,17 +825,6 @@ def to_csv(self):
self.comments,
)

@property
def display_name(self):
if self.name:
return self.name
elif self.virtual_chassis:
return f'{self.virtual_chassis.name}:{self.vc_position} ({self.pk})'
elif self.device_type:
return f'{self.device_type.manufacturer} {self.device_type.model} ({self.pk})'
else:
return '' # Device has not yet been created

@property
def identifier(self):
"""
Expand Down
10 changes: 3 additions & 7 deletions netbox/dcim/models/racks.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ class Meta:
)

def __str__(self):
return self.display_name or super().__str__()
if self.facility_id:
return f'{self.name} ({self.facility_id})'
return self.name

def get_absolute_url(self):
return reverse('dcim:rack', args=[self.pk])
Expand Down Expand Up @@ -277,12 +279,6 @@ def units(self):
else:
return reversed(range(1, self.u_height + 1))

@property
def display_name(self):
if self.facility_id:
return f'{self.name} ({self.facility_id})'
return self.name

def get_status_class(self):
return RackStatusChoices.CSS_CLASSES.get(self.status)

Expand Down
6 changes: 3 additions & 3 deletions netbox/dcim/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def setUpTestData(cls):

class RackTest(APIViewTestCases.APIViewTestCase):
model = Rack
brief_fields = ['device_count', 'display', 'display_name', 'id', 'name', 'url']
brief_fields = ['device_count', 'display', 'id', 'name', 'url']
bulk_update_data = {
'status': 'planned',
}
Expand Down Expand Up @@ -422,7 +422,7 @@ def setUpTestData(cls):

class DeviceTypeTest(APIViewTestCases.APIViewTestCase):
model = DeviceType
brief_fields = ['device_count', 'display', 'display_name', 'id', 'manufacturer', 'model', 'slug', 'url']
brief_fields = ['device_count', 'display', 'id', 'manufacturer', 'model', 'slug', 'url']
bulk_update_data = {
'part_number': 'ABC123',
}
Expand Down Expand Up @@ -870,7 +870,7 @@ def setUpTestData(cls):

class DeviceTest(APIViewTestCases.APIViewTestCase):
model = Device
brief_fields = ['display', 'display_name', 'id', 'name', 'url']
brief_fields = ['display', 'id', 'name', 'url']
bulk_update_data = {
'status': 'failed',
}
Expand Down
7 changes: 1 addition & 6 deletions netbox/extras/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,12 +453,7 @@ def get_changed_object(self, obj):

class ContentTypeSerializer(BaseModelSerializer):
url = serializers.HyperlinkedIdentityField(view_name='extras-api:contenttype-detail')
display_name = serializers.SerializerMethodField()

class Meta:
model = ContentType
fields = ['id', 'url', 'display', 'app_label', 'model', 'display_name']

@swagger_serializer_method(serializer_or_field=serializers.CharField)
def get_display_name(self, obj):
return obj.app_labeled_name
fields = ['id', 'url', 'display', 'app_label', 'model']
4 changes: 2 additions & 2 deletions netbox/ipam/api/nested_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class NestedVRFSerializer(WritableNestedSerializer):

class Meta:
model = models.VRF
fields = ['id', 'url', 'display', 'name', 'rd', 'display_name', 'prefix_count']
fields = ['id', 'url', 'display', 'name', 'rd', 'prefix_count']


#
Expand Down Expand Up @@ -92,7 +92,7 @@ class NestedVLANSerializer(WritableNestedSerializer):

class Meta:
model = models.VLAN
fields = ['id', 'url', 'display', 'vid', 'name', 'display_name']
fields = ['id', 'url', 'display', 'vid', 'name']


#
Expand Down
5 changes: 2 additions & 3 deletions netbox/ipam/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ class Meta:
model = VRF
fields = [
'id', 'url', 'display', 'name', 'rd', 'tenant', 'enforce_unique', 'description', 'import_targets',
'export_targets', 'tags', 'display_name', 'custom_fields', 'created', 'last_updated', 'ipaddress_count',
'prefix_count',
'export_targets', 'tags', 'custom_fields', 'created', 'last_updated', 'ipaddress_count', 'prefix_count',
]


Expand Down Expand Up @@ -167,7 +166,7 @@ class Meta:
model = VLAN
fields = [
'id', 'url', 'display', 'site', 'group', 'vid', 'name', 'tenant', 'status', 'role', 'description', 'tags',
'display_name', 'custom_fields', 'created', 'last_updated', 'prefix_count',
'custom_fields', 'created', 'last_updated', 'prefix_count',
]
validators = []

Expand Down
6 changes: 1 addition & 5 deletions netbox/ipam/models/vlans.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class Meta:
verbose_name_plural = 'VLANs'

def __str__(self):
return self.display_name or super().__str__()
return f'{self.name} ({self.vid})'

def get_absolute_url(self):
return reverse('ipam:vlan', args=[self.pk])
Expand All @@ -199,10 +199,6 @@ def to_csv(self):
self.description,
)

@property
def display_name(self):
return f'{self.name} ({self.vid})'

def get_status_class(self):
return VLANStatusChoices.CSS_CLASSES.get(self.status)

Expand Down
10 changes: 3 additions & 7 deletions netbox/ipam/models/vrfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ class Meta:
verbose_name_plural = 'VRFs'

def __str__(self):
return self.display_name or super().__str__()
if self.rd:
return f'{self.name} ({self.rd})'
return self.name

def get_absolute_url(self):
return reverse('ipam:vrf', args=[self.pk])
Expand All @@ -85,12 +87,6 @@ def to_csv(self):
self.description,
)

@property
def display_name(self):
if self.rd:
return f'{self.name} ({self.rd})'
return self.name


@extras_features('custom_fields', 'custom_links', 'export_templates', 'webhooks')
class RouteTarget(PrimaryModel):
Expand Down
4 changes: 2 additions & 2 deletions netbox/ipam/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_root(self):

class VRFTest(APIViewTestCases.APIViewTestCase):
model = VRF
brief_fields = ['display', 'display_name', 'id', 'name', 'prefix_count', 'rd', 'url']
brief_fields = ['display', 'id', 'name', 'prefix_count', 'rd', 'url']
create_data = [
{
'name': 'VRF 4',
Expand Down Expand Up @@ -421,7 +421,7 @@ def setUpTestData(cls):

class VLANTest(APIViewTestCases.APIViewTestCase):
model = VLAN
brief_fields = ['display', 'display_name', 'id', 'name', 'url', 'vid']
brief_fields = ['display', 'id', 'name', 'url', 'vid']
bulk_update_data = {
'description': 'New description',
}
Expand Down
4 changes: 2 additions & 2 deletions netbox/templates/dcim/device.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ <h5 class="card-header">
<tr>
<th scope="row">Device Type</th>
<td>
<span><a href="{{ object.device_type.get_absolute_url }}">{{ object.device_type.display_name }}</a> ({{ object.device_type.u_height }}U)</span>
<span><a href="{{ object.device_type.get_absolute_url }}">{{ object.device_type }}</a> ({{ object.device_type.u_height }}U)</span>
</td>
</tr>
<tr>
Expand Down Expand Up @@ -356,7 +356,7 @@ <h5 class="card-header">
<span class="text-muted">&mdash;</span>
{% endif %}
</td>
<td>{{ rd.device_type.display_name }}</td>
<td>{{ rd.device_type }}</td>
</tr>
{% endfor %}
</table>
Expand Down
2 changes: 1 addition & 1 deletion netbox/templates/dcim/rack.html
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ <h5 class="card-header">
<a href="{% url 'dcim:device' pk=device.pk %}">{{ device }}</a>
</td>
<td>{{ device.device_role }}</td>
<td>{{ device.device_type.display_name }}</td>
<td>{{ device.device_type }}</td>
{% if device.parent_bay %}
<td><a href="{{ device.parent_bay.device.get_absolute_url }}">{{ device.parent_bay.device }}</a></td>
<td>{{ device.parent_bay }}</td>
Expand Down
2 changes: 1 addition & 1 deletion netbox/templates/ipam/prefix.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ <h5 class="card-header">
{% if object.vlan.group %}
<a href="{{ object.vlan.group.get_absolute_url }}">{{ object.vlan.group }}</a> /
{% endif %}
<a href="{% url 'ipam:vlan' pk=object.vlan.pk %}">{{ object.vlan.display_name }}</a>
<a href="{% url 'ipam:vlan' pk=object.vlan.pk %}">{{ object.vlan }}</a>
{% else %}
<span class="text-muted">None</span>
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion netbox/templates/ipam/vlan/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% load helpers %}
{% load plugins %}

{% block title %}VLAN {{ object.display_name }}{% endblock %}
{% block title %}VLAN {{ object }}{% endblock %}

{% block breadcrumbs %}
<li class="breadcrumb-item">
Expand Down