mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Merge pull request #8441 from seulsale/8391-install-date-null
Fixes #8391: Install date should appear empty when exported
This commit is contained in:
@ -4,10 +4,13 @@ from django.contrib.auth.models import AnonymousUser
|
|||||||
from django.contrib.contenttypes.fields import GenericForeignKey
|
from django.contrib.contenttypes.fields import GenericForeignKey
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.core.exceptions import FieldDoesNotExist
|
from django.core.exceptions import FieldDoesNotExist
|
||||||
|
from django.db.models import DateField, DateTimeField
|
||||||
from django.db.models.fields.related import RelatedField
|
from django.db.models.fields.related import RelatedField
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
from django.utils.formats import date_format
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
from django_tables2 import RequestConfig
|
from django_tables2 import RequestConfig
|
||||||
|
from django_tables2.columns import library
|
||||||
from django_tables2.data import TableQuerysetData
|
from django_tables2.data import TableQuerysetData
|
||||||
from django_tables2.utils import Accessor
|
from django_tables2.utils import Accessor
|
||||||
|
|
||||||
@ -205,6 +208,42 @@ class TemplateColumn(tables.TemplateColumn):
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
@library.register
|
||||||
|
class DateColumn(tables.DateColumn):
|
||||||
|
"""
|
||||||
|
Overrides the default implementation of DateColumn to better handle null values, returning a default value for
|
||||||
|
tables and null when exporting data. It is registered in the tables library to use this class instead of the
|
||||||
|
default, making this behavior consistent in all fields of type DateField.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def value(self, value):
|
||||||
|
return value
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_field(cls, field, **kwargs):
|
||||||
|
if isinstance(field, DateField):
|
||||||
|
return cls(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
@library.register
|
||||||
|
class DateTimeColumn(tables.DateTimeColumn):
|
||||||
|
"""
|
||||||
|
Overrides the default implementation of DateTimeColumn to better handle null values, returning a default value for
|
||||||
|
tables and null when exporting data. It is registered in the tables library to use this class instead of the
|
||||||
|
default, making this behavior consistent in all fields of type DateTimeField.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def value(self, value):
|
||||||
|
if value:
|
||||||
|
return date_format(value, format="SHORT_DATETIME_FORMAT")
|
||||||
|
return None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_field(cls, field, **kwargs):
|
||||||
|
if isinstance(field, DateTimeField):
|
||||||
|
return cls(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
class ButtonsColumn(tables.TemplateColumn):
|
class ButtonsColumn(tables.TemplateColumn):
|
||||||
"""
|
"""
|
||||||
Render edit, delete, and changelog buttons for an object.
|
Render edit, delete, and changelog buttons for an object.
|
||||||
|
Reference in New Issue
Block a user