mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Introduce MPTTColumn to represent MPTT models
This commit is contained in:
@ -4,10 +4,10 @@ from django_tables2.utils import Accessor
|
|||||||
from dcim.models import Rack, Location, RackReservation, RackRole
|
from dcim.models import Rack, Location, RackReservation, RackRole
|
||||||
from tenancy.tables import TenantColumn
|
from tenancy.tables import TenantColumn
|
||||||
from utilities.tables import (
|
from utilities.tables import (
|
||||||
BaseTable, ButtonsColumn, ChoiceFieldColumn, ColorColumn, ColoredLabelColumn, LinkedCountColumn, TagColumn,
|
BaseTable, ButtonsColumn, ChoiceFieldColumn, ColorColumn, ColoredLabelColumn, LinkedCountColumn, MPTTColumn,
|
||||||
ToggleColumn,
|
TagColumn, ToggleColumn,
|
||||||
)
|
)
|
||||||
from .template_code import MPTT_LINK, LOCATION_ELEVATIONS, UTILIZATION_GRAPH
|
from .template_code import LOCATION_ELEVATIONS, UTILIZATION_GRAPH
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'RackTable',
|
'RackTable',
|
||||||
@ -24,11 +24,7 @@ __all__ = (
|
|||||||
|
|
||||||
class LocationTable(BaseTable):
|
class LocationTable(BaseTable):
|
||||||
pk = ToggleColumn()
|
pk = ToggleColumn()
|
||||||
name = tables.TemplateColumn(
|
name = MPTTColumn()
|
||||||
template_code=MPTT_LINK,
|
|
||||||
orderable=False,
|
|
||||||
attrs={'td': {'class': 'text-nowrap'}}
|
|
||||||
)
|
|
||||||
site = tables.Column(
|
site = tables.Column(
|
||||||
linkify=True
|
linkify=True
|
||||||
)
|
)
|
||||||
|
@ -2,8 +2,7 @@ import django_tables2 as tables
|
|||||||
|
|
||||||
from dcim.models import Region, Site
|
from dcim.models import Region, Site
|
||||||
from tenancy.tables import TenantColumn
|
from tenancy.tables import TenantColumn
|
||||||
from utilities.tables import BaseTable, ButtonsColumn, ChoiceFieldColumn, TagColumn, ToggleColumn
|
from utilities.tables import BaseTable, ButtonsColumn, ChoiceFieldColumn, MPTTColumn, TagColumn, ToggleColumn
|
||||||
from .template_code import MPTT_LINK
|
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'RegionTable',
|
'RegionTable',
|
||||||
@ -17,11 +16,7 @@ __all__ = (
|
|||||||
|
|
||||||
class RegionTable(BaseTable):
|
class RegionTable(BaseTable):
|
||||||
pk = ToggleColumn()
|
pk = ToggleColumn()
|
||||||
name = tables.TemplateColumn(
|
name = MPTTColumn()
|
||||||
template_code=MPTT_LINK,
|
|
||||||
orderable=False,
|
|
||||||
attrs={'td': {'class': 'text-nowrap'}}
|
|
||||||
)
|
|
||||||
site_count = tables.Column(
|
site_count = tables.Column(
|
||||||
verbose_name='Sites'
|
verbose_name='Sites'
|
||||||
)
|
)
|
||||||
|
@ -56,13 +56,6 @@ INTERFACE_TAGGED_VLANS = """
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
MPTT_LINK = """
|
|
||||||
{% for i in record.get_ancestors %}
|
|
||||||
<i class="mdi mdi-circle-small"></i>
|
|
||||||
{% endfor %}
|
|
||||||
<a href="{{ record.get_absolute_url }}">{{ record.name }}</a>
|
|
||||||
"""
|
|
||||||
|
|
||||||
POWERFEED_CABLE = """
|
POWERFEED_CABLE = """
|
||||||
<a href="{{ value.get_absolute_url }}">{{ value }}</a>
|
<a href="{{ value.get_absolute_url }}">{{ value }}</a>
|
||||||
<a href="{% url 'dcim:powerfeed_trace' pk=record.pk %}" class="btn btn-primary btn-xs" title="Trace">
|
<a href="{% url 'dcim:powerfeed_trace' pk=record.pk %}" class="btn btn-primary btn-xs" title="Trace">
|
||||||
|
@ -1,15 +1,8 @@
|
|||||||
import django_tables2 as tables
|
import django_tables2 as tables
|
||||||
|
|
||||||
from utilities.tables import BaseTable, ButtonsColumn, LinkedCountColumn, TagColumn, ToggleColumn
|
from utilities.tables import BaseTable, ButtonsColumn, LinkedCountColumn, MPTTColumn, TagColumn, ToggleColumn
|
||||||
from .models import Tenant, TenantGroup
|
from .models import Tenant, TenantGroup
|
||||||
|
|
||||||
MPTT_LINK = """
|
|
||||||
{% for i in record.get_ancestors %}
|
|
||||||
<i class="mdi mdi-circle-small"></i>
|
|
||||||
{% endfor %}
|
|
||||||
<a href="{{ record.get_absolute_url }}">{{ record.name }}</a>
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Table columns
|
# Table columns
|
||||||
@ -42,11 +35,7 @@ class TenantColumn(tables.TemplateColumn):
|
|||||||
|
|
||||||
class TenantGroupTable(BaseTable):
|
class TenantGroupTable(BaseTable):
|
||||||
pk = ToggleColumn()
|
pk = ToggleColumn()
|
||||||
name = tables.TemplateColumn(
|
name = MPTTColumn()
|
||||||
template_code=MPTT_LINK,
|
|
||||||
orderable=False,
|
|
||||||
attrs={'td': {'class': 'text-nowrap'}}
|
|
||||||
)
|
|
||||||
tenant_count = LinkedCountColumn(
|
tenant_count = LinkedCountColumn(
|
||||||
viewname='tenancy:tenant_list',
|
viewname='tenancy:tenant_list',
|
||||||
url_params={'group': 'slug'},
|
url_params={'group': 'slug'},
|
||||||
|
@ -287,3 +287,20 @@ class TagColumn(tables.TemplateColumn):
|
|||||||
|
|
||||||
def value(self, value):
|
def value(self, value):
|
||||||
return ",".join([tag.name for tag in value.all()])
|
return ",".join([tag.name for tag in value.all()])
|
||||||
|
|
||||||
|
|
||||||
|
class MPTTColumn(tables.TemplateColumn):
|
||||||
|
template_code = """{% for i in record.get_ancestors %}<i class="mdi mdi-circle-small"></i>{% endfor %}""" \
|
||||||
|
"""<a href="{{ record.get_absolute_url }}">{{ record.name }}</a>"""
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(
|
||||||
|
template_code=self.template_code,
|
||||||
|
orderable=False,
|
||||||
|
attrs={'td': {'class': 'text-nowrap'}},
|
||||||
|
*args,
|
||||||
|
**kwargs
|
||||||
|
)
|
||||||
|
|
||||||
|
def value(self, value):
|
||||||
|
return value
|
||||||
|
Reference in New Issue
Block a user