mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-26 09:16:10 -06:00
12552 cleanup mptt
This commit is contained in:
parent
9ee6511194
commit
ff9a9d914f
@ -1157,7 +1157,7 @@ class InventoryItem(TreeNode, ComponentModel):
|
|||||||
})
|
})
|
||||||
|
|
||||||
# Prevent moving InventoryItems with children
|
# 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:
|
if first_child and first_child.device != self.device:
|
||||||
raise ValidationError("Cannot move an inventory item with dependent children")
|
raise ValidationError("Cannot move an inventory item with dependent children")
|
||||||
|
|
||||||
|
@ -866,7 +866,7 @@ class Device(PrimaryModel, ConfigContextModel):
|
|||||||
self._instantiate_components(self.device_type.frontporttemplates.all())
|
self._instantiate_components(self.device_type.frontporttemplates.all())
|
||||||
self._instantiate_components(self.device_type.modulebaytemplates.all())
|
self._instantiate_components(self.device_type.modulebaytemplates.all())
|
||||||
self._instantiate_components(self.device_type.devicebaytemplates.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)
|
self._instantiate_components(self.device_type.inventoryitemtemplates.all(), bulk_create=False)
|
||||||
# Interface bridges have to be set after interface instantiation
|
# Interface bridges have to be set after interface instantiation
|
||||||
update_interface_bridges(self, self.device_type.interfacetemplates.all())
|
update_interface_bridges(self, self.device_type.interfacetemplates.all())
|
||||||
|
@ -36,7 +36,7 @@ def get_device_name(device):
|
|||||||
else:
|
else:
|
||||||
name = str(device.device_type)
|
name = str(device.device_type)
|
||||||
if device.devicebay_count:
|
if device.devicebay_count:
|
||||||
name += ' ({}/{})'.format(device.get_children().count(), device.devicebay_count)
|
name += ' ({}/{})'.format(device.children.count(), device.devicebay_count)
|
||||||
|
|
||||||
return name
|
return name
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ __all__ = (
|
|||||||
#
|
#
|
||||||
|
|
||||||
class RegionTable(ContactsColumnMixin, NetBoxTable):
|
class RegionTable(ContactsColumnMixin, NetBoxTable):
|
||||||
name = columns.MPTTColumn(
|
name = columns.TreeColumn(
|
||||||
linkify=True
|
linkify=True
|
||||||
)
|
)
|
||||||
site_count = columns.LinkedCountColumn(
|
site_count = columns.LinkedCountColumn(
|
||||||
@ -45,7 +45,7 @@ class RegionTable(ContactsColumnMixin, NetBoxTable):
|
|||||||
#
|
#
|
||||||
|
|
||||||
class SiteGroupTable(ContactsColumnMixin, NetBoxTable):
|
class SiteGroupTable(ContactsColumnMixin, NetBoxTable):
|
||||||
name = columns.MPTTColumn(
|
name = columns.TreeColumn(
|
||||||
linkify=True
|
linkify=True
|
||||||
)
|
)
|
||||||
site_count = columns.LinkedCountColumn(
|
site_count = columns.LinkedCountColumn(
|
||||||
@ -111,7 +111,7 @@ class SiteTable(TenancyColumnsMixin, ContactsColumnMixin, NetBoxTable):
|
|||||||
#
|
#
|
||||||
|
|
||||||
class LocationTable(TenancyColumnsMixin, ContactsColumnMixin, NetBoxTable):
|
class LocationTable(TenancyColumnsMixin, ContactsColumnMixin, NetBoxTable):
|
||||||
name = columns.MPTTColumn(
|
name = columns.TreeColumn(
|
||||||
linkify=True
|
linkify=True
|
||||||
)
|
)
|
||||||
site = tables.Column(
|
site = tables.Column(
|
||||||
|
@ -19,7 +19,7 @@ class NetBoxModelSerializer(TaggableModelSerializer, CustomFieldModelSerializer,
|
|||||||
|
|
||||||
class NestedGroupModelSerializer(NetBoxModelSerializer):
|
class NestedGroupModelSerializer(NetBoxModelSerializer):
|
||||||
"""
|
"""
|
||||||
Extends PrimaryModelSerializer to include MPTT support.
|
Extends PrimaryModelSerializer to include Tree support.
|
||||||
"""
|
"""
|
||||||
_depth = serializers.IntegerField(source='tree_depth', read_only=True)
|
_depth = serializers.IntegerField(source='tree_depth', read_only=True)
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ __all__ = (
|
|||||||
'LinkedCountColumn',
|
'LinkedCountColumn',
|
||||||
'MarkdownColumn',
|
'MarkdownColumn',
|
||||||
'ManyToManyColumn',
|
'ManyToManyColumn',
|
||||||
'MPTTColumn',
|
'TreeColumn',
|
||||||
'TagColumn',
|
'TagColumn',
|
||||||
'TemplateColumn',
|
'TemplateColumn',
|
||||||
'ToggleColumn',
|
'ToggleColumn',
|
||||||
@ -531,9 +531,9 @@ class CustomLinkColumn(tables.Column):
|
|||||||
return None
|
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 = """
|
template_code = """
|
||||||
{% load helpers %}
|
{% load helpers %}
|
||||||
|
@ -13,7 +13,7 @@ __all__ = (
|
|||||||
|
|
||||||
|
|
||||||
class ContactGroupTable(NetBoxTable):
|
class ContactGroupTable(NetBoxTable):
|
||||||
name = columns.MPTTColumn(
|
name = columns.TreeColumn(
|
||||||
linkify=True
|
linkify=True
|
||||||
)
|
)
|
||||||
contact_count = columns.LinkedCountColumn(
|
contact_count = columns.LinkedCountColumn(
|
||||||
|
@ -11,7 +11,7 @@ __all__ = (
|
|||||||
|
|
||||||
|
|
||||||
class TenantGroupTable(NetBoxTable):
|
class TenantGroupTable(NetBoxTable):
|
||||||
name = columns.MPTTColumn(
|
name = columns.TreeColumn(
|
||||||
linkify=True
|
linkify=True
|
||||||
)
|
)
|
||||||
tenant_count = columns.LinkedCountColumn(
|
tenant_count = columns.LinkedCountColumn(
|
||||||
|
@ -418,7 +418,7 @@ class APIViewTestCases:
|
|||||||
obj_perm.object_types.add(ContentType.objects.get_for_model(self.model))
|
obj_perm.object_types.add(ContentType.objects.get_for_model(self.model))
|
||||||
|
|
||||||
# Target the three most recently created objects to avoid triggering recursive deletions
|
# 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])
|
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")
|
self.assertEqual(len(id_list), 3, "Insufficient number of objects to test bulk deletion")
|
||||||
data = [{"id": id} for id in id_list]
|
data = [{"id": id} for id in id_list]
|
||||||
|
@ -13,7 +13,7 @@ __all__ = (
|
|||||||
|
|
||||||
|
|
||||||
class WirelessLANGroupTable(NetBoxTable):
|
class WirelessLANGroupTable(NetBoxTable):
|
||||||
name = columns.MPTTColumn(
|
name = columns.TreeColumn(
|
||||||
linkify=True
|
linkify=True
|
||||||
)
|
)
|
||||||
wirelesslan_count = columns.LinkedCountColumn(
|
wirelesslan_count = columns.LinkedCountColumn(
|
||||||
|
Loading…
Reference in New Issue
Block a user