diff --git a/netbox/dcim/tables.py b/netbox/dcim/tables.py
index 1053287f7..7af030a03 100644
--- a/netbox/dcim/tables.py
+++ b/netbox/dcim/tables.py
@@ -24,19 +24,6 @@ MPTT_LINK = """
"""
-SITE_REGION_LINK = """
-{% if record.region %}
- {{ record.region }}
-{% else %}
- —
-{% endif %}
-"""
-
-COLOR_LABEL = """
-{% load helpers %}
-
-"""
-
DEVICE_LINK = """
{{ record.name|default:'Unnamed device' }}
@@ -49,39 +36,6 @@ RACKGROUP_ELEVATIONS = """
"""
-RACKRESERVATION_ACTIONS = """
-
-
-
-{% if perms.dcim.change_rackreservation %}
-
-{% endif %}
-"""
-
-MANUFACTURER_ACTIONS = """
-
-
-
-{% if perms.dcim.change_manufacturer %}
-
-{% endif %}
-"""
-
-DEVICEROLE_ACTIONS = """
-
-
-
-{% if perms.dcim.change_devicerole %}
-
-{% endif %}
-"""
-
-DEVICE_PRIMARY_IP = """
-{{ record.primary_ip6.address.ip|default:"" }}
-{% if record.primary_ip6 and record.primary_ip4 %}
{% endif %}
-{{ record.primary_ip4.address.ip|default:"" }}
-"""
-
UTILIZATION_GRAPH = """
{% load helpers %}
{% utilization_graph value %}
@@ -149,8 +103,8 @@ class SiteTable(BaseTable):
order_by=('_name',)
)
status = ChoiceFieldColumn()
- region = tables.TemplateColumn(
- template_code=SITE_REGION_LINK
+ region = tables.Column(
+ linkify=True
)
tenant = tables.TemplateColumn(
template_code=COL_TENANT
@@ -206,7 +160,7 @@ class RackRoleTable(BaseTable):
pk = ToggleColumn()
name = tables.Column(linkify=True)
rack_count = tables.Column(verbose_name='Racks')
- color = tables.TemplateColumn(COLOR_LABEL)
+ color = ColorColumn()
actions = ButtonsColumn(RackRole)
class Meta(BaseTable.Meta):
@@ -506,10 +460,7 @@ class DeviceRoleTable(BaseTable):
url_params={'role': 'slug'},
verbose_name='VMs'
)
- color = tables.TemplateColumn(
- template_code=COLOR_LABEL,
- verbose_name='Label'
- )
+ color = ColorColumn()
vm_role = BooleanColumn()
actions = ButtonsColumn(DeviceRole, pk_field='slug')
@@ -577,9 +528,8 @@ class DeviceTable(BaseTable):
verbose_name='Type',
text=lambda record: record.device_type.display_name
)
- primary_ip = tables.TemplateColumn(
- template_code=DEVICE_PRIMARY_IP,
- orderable=False,
+ primary_ip = tables.Column(
+ linkify=True,
verbose_name='IP Address'
)
primary_ip4 = tables.Column(
diff --git a/netbox/extras/choices.py b/netbox/extras/choices.py
index 7e1e7a036..45f8ac31f 100644
--- a/netbox/extras/choices.py
+++ b/netbox/extras/choices.py
@@ -78,6 +78,12 @@ class ObjectChangeActionChoices(ChoiceSet):
(ACTION_DELETE, 'Deleted'),
)
+ CSS_CLASSES = {
+ ACTION_CREATE: 'success',
+ ACTION_UPDATE: 'primary',
+ ACTION_DELETE: 'danger',
+ }
+
#
# Log Levels for Reports and Scripts
diff --git a/netbox/extras/models/change_logging.py b/netbox/extras/models/change_logging.py
index bec8e2b75..d03dab00a 100644
--- a/netbox/extras/models/change_logging.py
+++ b/netbox/extras/models/change_logging.py
@@ -152,3 +152,6 @@ class ObjectChange(models.Model):
self.object_repr,
self.object_data,
)
+
+ def get_action_class(self):
+ return ObjectChangeActionChoices.CSS_CLASSES.get(self.action)
diff --git a/netbox/extras/tables.py b/netbox/extras/tables.py
index 7980bdcc1..8db8f6c57 100644
--- a/netbox/extras/tables.py
+++ b/netbox/extras/tables.py
@@ -1,6 +1,7 @@
import django_tables2 as tables
+from django.conf import settings
-from utilities.tables import BaseTable, BooleanColumn, ButtonsColumn, ColorColumn, ToggleColumn
+from utilities.tables import BaseTable, BooleanColumn, ButtonsColumn, ChoiceFieldColumn, ColorColumn, ToggleColumn
from .models import ConfigContext, ObjectChange, Tag, TaggedItem
TAGGED_ITEM = """
@@ -20,20 +21,6 @@ CONFIGCONTEXT_ACTIONS = """
{% endif %}
"""
-OBJECTCHANGE_TIME = """
-{{ value|date:"SHORT_DATETIME_FORMAT" }}
-"""
-
-OBJECTCHANGE_ACTION = """
-{% if record.action == 'create' %}
- Created
-{% elif record.action == 'update' %}
- Updated
-{% elif record.action == 'delete' %}
- Deleted
-{% endif %}
-"""
-
OBJECTCHANGE_OBJECT = """
{% if record.action != 3 and record.changed_object.get_absolute_url %}
{{ record.object_repr }}
@@ -91,12 +78,11 @@ class ConfigContextTable(BaseTable):
class ObjectChangeTable(BaseTable):
- time = tables.TemplateColumn(
- template_code=OBJECTCHANGE_TIME
- )
- action = tables.TemplateColumn(
- template_code=OBJECTCHANGE_ACTION
+ time = tables.DateTimeColumn(
+ linkify=True,
+ format=settings.SHORT_DATETIME_FORMAT
)
+ action = ChoiceFieldColumn()
changed_object_type = tables.Column(
verbose_name='Type'
)
diff --git a/netbox/ipam/tables.py b/netbox/ipam/tables.py
index 1d2ff9243..c6381a37a 100644
--- a/netbox/ipam/tables.py
+++ b/netbox/ipam/tables.py
@@ -78,14 +78,6 @@ VRF_LINK = """
{% endif %}
"""
-STATUS_LABEL = """
-{% if record.pk %}
- {{ record.get_status_display }}
-{% else %}
- Available
-{% endif %}
-"""
-
VLAN_LINK = """
{% if record.pk %}
{{ record.vid }}
@@ -130,12 +122,6 @@ VLAN_MEMBER_TAGGED = """
{% endif %}
"""
-VLAN_MEMBER_ACTIONS = """
-{% if perms.dcim.change_interface %}
-
-{% endif %}
-"""
-
TENANT_LINK = """
{% if record.tenant %}
{{ record.tenant }}
@@ -587,15 +573,11 @@ class VLANMembersTable(BaseTable):
template_code=VLAN_MEMBER_TAGGED,
orderable=False
)
- actions = tables.TemplateColumn(
- template_code=VLAN_MEMBER_ACTIONS,
- attrs={'td': {'class': 'text-right noprint'}},
- verbose_name=''
- )
class VLANDevicesTable(VLANMembersTable):
device = tables.LinkColumn()
+ actions = ButtonsColumn(Interface, buttons=['edit'])
class Meta(BaseTable.Meta):
model = Interface
@@ -604,6 +586,7 @@ class VLANDevicesTable(VLANMembersTable):
class VLANVirtualMachinesTable(VLANMembersTable):
virtual_machine = tables.LinkColumn()
+ actions = ButtonsColumn(VMInterface, buttons=['edit'])
class Meta(BaseTable.Meta):
model = VMInterface
diff --git a/netbox/utilities/tables.py b/netbox/utilities/tables.py
index d4861c93a..ff19bb4dc 100644
--- a/netbox/utilities/tables.py
+++ b/netbox/utilities/tables.py
@@ -197,7 +197,7 @@ class ColorColumn(tables.Column):
"""
def render(self, value):
return mark_safe(
- ' '.format(value)
+ f' '
)
diff --git a/netbox/virtualization/tables.py b/netbox/virtualization/tables.py
index 81cf986d8..7acae4cc0 100644
--- a/netbox/virtualization/tables.py
+++ b/netbox/virtualization/tables.py
@@ -7,12 +7,6 @@ from utilities.tables import (
)
from .models import Cluster, ClusterGroup, ClusterType, VirtualMachine, VMInterface
-VIRTUALMACHINE_PRIMARY_IP = """
-{{ record.primary_ip6.address.ip|default:"" }}
-{% if record.primary_ip6 and record.primary_ip4 %}
{% endif %}
-{{ record.primary_ip4.address.ip|default:"" }}
-"""
-
#
# Cluster types
@@ -113,10 +107,9 @@ class VirtualMachineDetailTable(VirtualMachineTable):
linkify=True,
verbose_name='IPv6 Address'
)
- primary_ip = tables.TemplateColumn(
- orderable=False,
- verbose_name='IP Address',
- template_code=VIRTUALMACHINE_PRIMARY_IP
+ primary_ip = tables.Column(
+ linkify=True,
+ verbose_name='IP Address'
)
tags = TagColumn(
url_name='virtualization:virtualmachine_list'