12552 cleanup mptt

This commit is contained in:
Arthur 2023-05-24 15:40:29 -07:00
parent 9ee6511194
commit ff9a9d914f
10 changed files with 14 additions and 14 deletions

View File

@ -1157,7 +1157,7 @@ class InventoryItem(TreeNode, ComponentModel):
})
# Prevent moving InventoryItems with children
first_child = self.get_children().first()
first_child = self.children.first()
if first_child and first_child.device != self.device:
raise ValidationError("Cannot move an inventory item with dependent children")

View File

@ -866,7 +866,7 @@ class Device(PrimaryModel, ConfigContextModel):
self._instantiate_components(self.device_type.frontporttemplates.all())
self._instantiate_components(self.device_type.modulebaytemplates.all())
self._instantiate_components(self.device_type.devicebaytemplates.all())
# Disable bulk_create to accommodate MPTT
# Disable bulk_create to accommodate django-tree-queries
self._instantiate_components(self.device_type.inventoryitemtemplates.all(), bulk_create=False)
# Interface bridges have to be set after interface instantiation
update_interface_bridges(self, self.device_type.interfacetemplates.all())

View File

@ -36,7 +36,7 @@ def get_device_name(device):
else:
name = str(device.device_type)
if device.devicebay_count:
name += ' ({}/{})'.format(device.get_children().count(), device.devicebay_count)
name += ' ({}/{})'.format(device.children.count(), device.devicebay_count)
return name

View File

@ -19,7 +19,7 @@ __all__ = (
#
class RegionTable(ContactsColumnMixin, NetBoxTable):
name = columns.MPTTColumn(
name = columns.TreeColumn(
linkify=True
)
site_count = columns.LinkedCountColumn(
@ -45,7 +45,7 @@ class RegionTable(ContactsColumnMixin, NetBoxTable):
#
class SiteGroupTable(ContactsColumnMixin, NetBoxTable):
name = columns.MPTTColumn(
name = columns.TreeColumn(
linkify=True
)
site_count = columns.LinkedCountColumn(
@ -111,7 +111,7 @@ class SiteTable(TenancyColumnsMixin, ContactsColumnMixin, NetBoxTable):
#
class LocationTable(TenancyColumnsMixin, ContactsColumnMixin, NetBoxTable):
name = columns.MPTTColumn(
name = columns.TreeColumn(
linkify=True
)
site = tables.Column(

View File

@ -19,7 +19,7 @@ class NetBoxModelSerializer(TaggableModelSerializer, CustomFieldModelSerializer,
class NestedGroupModelSerializer(NetBoxModelSerializer):
"""
Extends PrimaryModelSerializer to include MPTT support.
Extends PrimaryModelSerializer to include Tree support.
"""
_depth = serializers.IntegerField(source='tree_depth', read_only=True)

View File

@ -33,7 +33,7 @@ __all__ = (
'LinkedCountColumn',
'MarkdownColumn',
'ManyToManyColumn',
'MPTTColumn',
'TreeColumn',
'TagColumn',
'TemplateColumn',
'ToggleColumn',
@ -531,9 +531,9 @@ class CustomLinkColumn(tables.Column):
return None
class MPTTColumn(tables.TemplateColumn):
class TreeColumn(tables.TemplateColumn):
"""
Display a nested hierarchy for MPTT-enabled models.
Display a nested hierarchy for Tree-enabled models.
"""
template_code = """
{% load helpers %}

View File

@ -13,7 +13,7 @@ __all__ = (
class ContactGroupTable(NetBoxTable):
name = columns.MPTTColumn(
name = columns.TreeColumn(
linkify=True
)
contact_count = columns.LinkedCountColumn(

View File

@ -11,7 +11,7 @@ __all__ = (
class TenantGroupTable(NetBoxTable):
name = columns.MPTTColumn(
name = columns.TreeColumn(
linkify=True
)
tenant_count = columns.LinkedCountColumn(

View File

@ -418,7 +418,7 @@ class APIViewTestCases:
obj_perm.object_types.add(ContentType.objects.get_for_model(self.model))
# Target the three most recently created objects to avoid triggering recursive deletions
# (e.g. with MPTT objects)
# (e.g. with django-tree-queries objects)
id_list = list(self._get_queryset().order_by('-id').values_list('id', flat=True)[:3])
self.assertEqual(len(id_list), 3, "Insufficient number of objects to test bulk deletion")
data = [{"id": id} for id in id_list]

View File

@ -13,7 +13,7 @@ __all__ = (
class WirelessLANGroupTable(NetBoxTable):
name = columns.MPTTColumn(
name = columns.TreeColumn(
linkify=True
)
wirelesslan_count = columns.LinkedCountColumn(