mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-24 17:38:37 -06:00
Closes #5998: Introduce ContentTypeColumn
This commit is contained in:
parent
9a68a61ad3
commit
889316085c
@ -1,7 +1,9 @@
|
|||||||
import django_tables2 as tables
|
import django_tables2 as tables
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
from utilities.tables import BaseTable, BooleanColumn, ButtonsColumn, ChoiceFieldColumn, ColorColumn, ToggleColumn
|
from utilities.tables import (
|
||||||
|
BaseTable, BooleanColumn, ButtonsColumn, ChoiceFieldColumn, ColorColumn, ContentTypeColumn, ToggleColumn,
|
||||||
|
)
|
||||||
from .models import ConfigContext, JournalEntry, ObjectChange, Tag, TaggedItem
|
from .models import ConfigContext, JournalEntry, ObjectChange, Tag, TaggedItem
|
||||||
|
|
||||||
TAGGED_ITEM = """
|
TAGGED_ITEM = """
|
||||||
@ -81,7 +83,7 @@ class ObjectChangeTable(BaseTable):
|
|||||||
format=settings.SHORT_DATETIME_FORMAT
|
format=settings.SHORT_DATETIME_FORMAT
|
||||||
)
|
)
|
||||||
action = ChoiceFieldColumn()
|
action = ChoiceFieldColumn()
|
||||||
changed_object_type = tables.Column(
|
changed_object_type = ContentTypeColumn(
|
||||||
verbose_name='Type'
|
verbose_name='Type'
|
||||||
)
|
)
|
||||||
object_repr = tables.TemplateColumn(
|
object_repr = tables.TemplateColumn(
|
||||||
@ -103,7 +105,7 @@ class JournalEntryTable(BaseTable):
|
|||||||
created = tables.DateTimeColumn(
|
created = tables.DateTimeColumn(
|
||||||
format=settings.SHORT_DATETIME_FORMAT
|
format=settings.SHORT_DATETIME_FORMAT
|
||||||
)
|
)
|
||||||
assigned_object_type = tables.Column(
|
assigned_object_type = ContentTypeColumn(
|
||||||
verbose_name='Object type'
|
verbose_name='Object type'
|
||||||
)
|
)
|
||||||
assigned_object = tables.Column(
|
assigned_object = tables.Column(
|
||||||
|
@ -5,8 +5,8 @@ from django_tables2.utils import Accessor
|
|||||||
from dcim.models import Interface
|
from dcim.models import Interface
|
||||||
from tenancy.tables import TenantColumn
|
from tenancy.tables import TenantColumn
|
||||||
from utilities.tables import (
|
from utilities.tables import (
|
||||||
BaseTable, BooleanColumn, ButtonsColumn, ChoiceFieldColumn, LinkedCountColumn, TagColumn, ToggleColumn,
|
BaseTable, BooleanColumn, ButtonsColumn, ChoiceFieldColumn, ContentTypeColumn, LinkedCountColumn, TagColumn,
|
||||||
UtilizationColumn,
|
ToggleColumn, UtilizationColumn,
|
||||||
)
|
)
|
||||||
from virtualization.models import VMInterface
|
from virtualization.models import VMInterface
|
||||||
from .models import Aggregate, IPAddress, Prefix, RIR, Role, RouteTarget, Service, VLAN, VLANGroup, VRF
|
from .models import Aggregate, IPAddress, Prefix, RIR, Role, RouteTarget, Service, VLAN, VLANGroup, VRF
|
||||||
@ -417,6 +417,7 @@ class InterfaceIPAddressTable(BaseTable):
|
|||||||
class VLANGroupTable(BaseTable):
|
class VLANGroupTable(BaseTable):
|
||||||
pk = ToggleColumn()
|
pk = ToggleColumn()
|
||||||
name = tables.Column(linkify=True)
|
name = tables.Column(linkify=True)
|
||||||
|
scope_type = ContentTypeColumn()
|
||||||
scope = tables.Column(
|
scope = tables.Column(
|
||||||
linkify=True
|
linkify=True
|
||||||
)
|
)
|
||||||
|
@ -212,6 +212,17 @@ class ChoiceFieldColumn(tables.Column):
|
|||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
class ContentTypeColumn(tables.Column):
|
||||||
|
"""
|
||||||
|
Display a ContentType instance.
|
||||||
|
"""
|
||||||
|
def render(self, value):
|
||||||
|
return value.name[0].upper() + value.name[1:]
|
||||||
|
|
||||||
|
def value(self, value):
|
||||||
|
return f"{value.app_label}.{value.model}"
|
||||||
|
|
||||||
|
|
||||||
class ColorColumn(tables.Column):
|
class ColorColumn(tables.Column):
|
||||||
"""
|
"""
|
||||||
Display a color (#RRGGBB).
|
Display a color (#RRGGBB).
|
||||||
|
Loading…
Reference in New Issue
Block a user