mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-15 12:08:17 -06:00
Standardize the use of DateTimeColumn across all tables
This commit is contained in:
parent
cdbb700c8f
commit
2dea0ac1d3
@ -31,9 +31,11 @@ class UserTokenTable(NetBoxTable):
|
|||||||
verbose_name=_('Write Enabled')
|
verbose_name=_('Write Enabled')
|
||||||
)
|
)
|
||||||
created = columns.DateTimeColumn(
|
created = columns.DateTimeColumn(
|
||||||
|
timespec='minutes',
|
||||||
verbose_name=_('Created'),
|
verbose_name=_('Created'),
|
||||||
)
|
)
|
||||||
expires = columns.DateTimeColumn(
|
expires = columns.DateTimeColumn(
|
||||||
|
timespec='minutes',
|
||||||
verbose_name=_('Expires'),
|
verbose_name=_('Expires'),
|
||||||
)
|
)
|
||||||
last_used = columns.DateTimeColumn(
|
last_used = columns.DateTimeColumn(
|
||||||
|
@ -3,7 +3,7 @@ from django.utils.translation import gettext_lazy as _
|
|||||||
from django_tables2.utils import A
|
from django_tables2.utils import A
|
||||||
|
|
||||||
from core.tables.columns import RQJobStatusColumn
|
from core.tables.columns import RQJobStatusColumn
|
||||||
from netbox.tables import BaseTable
|
from netbox.tables import BaseTable, columns
|
||||||
|
|
||||||
|
|
||||||
class BackgroundQueueTable(BaseTable):
|
class BackgroundQueueTable(BaseTable):
|
||||||
@ -75,13 +75,13 @@ class BackgroundTaskTable(BaseTable):
|
|||||||
linkify=("core:background_task", [A("id")]),
|
linkify=("core:background_task", [A("id")]),
|
||||||
verbose_name=_("ID")
|
verbose_name=_("ID")
|
||||||
)
|
)
|
||||||
created_at = tables.DateTimeColumn(
|
created_at = columns.DateTimeColumn(
|
||||||
verbose_name=_("Created")
|
verbose_name=_("Created")
|
||||||
)
|
)
|
||||||
enqueued_at = tables.DateTimeColumn(
|
enqueued_at = columns.DateTimeColumn(
|
||||||
verbose_name=_("Enqueued")
|
verbose_name=_("Enqueued")
|
||||||
)
|
)
|
||||||
ended_at = tables.DateTimeColumn(
|
ended_at = columns.DateTimeColumn(
|
||||||
verbose_name=_("Ended")
|
verbose_name=_("Ended")
|
||||||
)
|
)
|
||||||
status = RQJobStatusColumn(
|
status = RQJobStatusColumn(
|
||||||
@ -117,7 +117,7 @@ class WorkerTable(BaseTable):
|
|||||||
state = tables.Column(
|
state = tables.Column(
|
||||||
verbose_name=_("State")
|
verbose_name=_("State")
|
||||||
)
|
)
|
||||||
birth_date = tables.DateTimeColumn(
|
birth_date = columns.DateTimeColumn(
|
||||||
verbose_name=_("Birth")
|
verbose_name=_("Birth")
|
||||||
)
|
)
|
||||||
pid = tables.Column(
|
pid = tables.Column(
|
||||||
|
@ -432,10 +432,10 @@ class ConfigTemplateTable(NetBoxTable):
|
|||||||
|
|
||||||
|
|
||||||
class ObjectChangeTable(NetBoxTable):
|
class ObjectChangeTable(NetBoxTable):
|
||||||
time = tables.DateTimeColumn(
|
time = columns.DateTimeColumn(
|
||||||
verbose_name=_('Time'),
|
verbose_name=_('Time'),
|
||||||
linkify=True,
|
timespec='minutes',
|
||||||
format=settings.SHORT_DATETIME_FORMAT
|
linkify=True
|
||||||
)
|
)
|
||||||
user_name = tables.Column(
|
user_name = tables.Column(
|
||||||
verbose_name=_('Username')
|
verbose_name=_('Username')
|
||||||
@ -475,10 +475,10 @@ class ObjectChangeTable(NetBoxTable):
|
|||||||
|
|
||||||
|
|
||||||
class JournalEntryTable(NetBoxTable):
|
class JournalEntryTable(NetBoxTable):
|
||||||
created = tables.DateTimeColumn(
|
created = columns.DateTimeColumn(
|
||||||
verbose_name=_('Created'),
|
verbose_name=_('Created'),
|
||||||
linkify=True,
|
timespec='minutes',
|
||||||
format=settings.SHORT_DATETIME_FORMAT
|
linkify=True
|
||||||
)
|
)
|
||||||
assigned_object_type = columns.ContentTypeColumn(
|
assigned_object_type = columns.ContentTypeColumn(
|
||||||
verbose_name=_('Object Type')
|
verbose_name=_('Object Type')
|
||||||
|
@ -73,14 +73,21 @@ class DateColumn(tables.Column):
|
|||||||
class DateTimeColumn(tables.Column):
|
class DateTimeColumn(tables.Column):
|
||||||
"""
|
"""
|
||||||
Render a datetime.datetime in ISO 8601 format.
|
Render a datetime.datetime in ISO 8601 format.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
timespec: Granularity specification; passed through to datetime.isoformat()
|
||||||
"""
|
"""
|
||||||
|
def __init__(self, *args, timespec='seconds', **kwargs):
|
||||||
|
self.timespec = timespec
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
def render(self, value):
|
def render(self, value):
|
||||||
if value:
|
if value:
|
||||||
return f"{value.date().isoformat()} {value.time().isoformat(timespec='seconds')}"
|
return f"{value.date().isoformat()} {value.time().isoformat(timespec=self.timespec)}"
|
||||||
|
|
||||||
def value(self, value):
|
def value(self, value):
|
||||||
if value:
|
if value:
|
||||||
return value.isoformat(timespec='seconds')
|
return value.isoformat()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_field(cls, field, **kwargs):
|
def from_field(cls, field, **kwargs):
|
||||||
|
Loading…
Reference in New Issue
Block a user