mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-13 19:18:16 -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')
|
||||
)
|
||||
created = columns.DateTimeColumn(
|
||||
timespec='minutes',
|
||||
verbose_name=_('Created'),
|
||||
)
|
||||
expires = columns.DateTimeColumn(
|
||||
timespec='minutes',
|
||||
verbose_name=_('Expires'),
|
||||
)
|
||||
last_used = columns.DateTimeColumn(
|
||||
|
@ -3,7 +3,7 @@ from django.utils.translation import gettext_lazy as _
|
||||
from django_tables2.utils import A
|
||||
|
||||
from core.tables.columns import RQJobStatusColumn
|
||||
from netbox.tables import BaseTable
|
||||
from netbox.tables import BaseTable, columns
|
||||
|
||||
|
||||
class BackgroundQueueTable(BaseTable):
|
||||
@ -75,13 +75,13 @@ class BackgroundTaskTable(BaseTable):
|
||||
linkify=("core:background_task", [A("id")]),
|
||||
verbose_name=_("ID")
|
||||
)
|
||||
created_at = tables.DateTimeColumn(
|
||||
created_at = columns.DateTimeColumn(
|
||||
verbose_name=_("Created")
|
||||
)
|
||||
enqueued_at = tables.DateTimeColumn(
|
||||
enqueued_at = columns.DateTimeColumn(
|
||||
verbose_name=_("Enqueued")
|
||||
)
|
||||
ended_at = tables.DateTimeColumn(
|
||||
ended_at = columns.DateTimeColumn(
|
||||
verbose_name=_("Ended")
|
||||
)
|
||||
status = RQJobStatusColumn(
|
||||
@ -117,7 +117,7 @@ class WorkerTable(BaseTable):
|
||||
state = tables.Column(
|
||||
verbose_name=_("State")
|
||||
)
|
||||
birth_date = tables.DateTimeColumn(
|
||||
birth_date = columns.DateTimeColumn(
|
||||
verbose_name=_("Birth")
|
||||
)
|
||||
pid = tables.Column(
|
||||
|
@ -432,10 +432,10 @@ class ConfigTemplateTable(NetBoxTable):
|
||||
|
||||
|
||||
class ObjectChangeTable(NetBoxTable):
|
||||
time = tables.DateTimeColumn(
|
||||
time = columns.DateTimeColumn(
|
||||
verbose_name=_('Time'),
|
||||
linkify=True,
|
||||
format=settings.SHORT_DATETIME_FORMAT
|
||||
timespec='minutes',
|
||||
linkify=True
|
||||
)
|
||||
user_name = tables.Column(
|
||||
verbose_name=_('Username')
|
||||
@ -475,10 +475,10 @@ class ObjectChangeTable(NetBoxTable):
|
||||
|
||||
|
||||
class JournalEntryTable(NetBoxTable):
|
||||
created = tables.DateTimeColumn(
|
||||
created = columns.DateTimeColumn(
|
||||
verbose_name=_('Created'),
|
||||
linkify=True,
|
||||
format=settings.SHORT_DATETIME_FORMAT
|
||||
timespec='minutes',
|
||||
linkify=True
|
||||
)
|
||||
assigned_object_type = columns.ContentTypeColumn(
|
||||
verbose_name=_('Object Type')
|
||||
|
@ -73,14 +73,21 @@ class DateColumn(tables.Column):
|
||||
class DateTimeColumn(tables.Column):
|
||||
"""
|
||||
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):
|
||||
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):
|
||||
if value:
|
||||
return value.isoformat(timespec='seconds')
|
||||
return value.isoformat()
|
||||
|
||||
@classmethod
|
||||
def from_field(cls, field, **kwargs):
|
||||
|
Loading…
Reference in New Issue
Block a user