network_inventory/devices/tables.py

51 lines
1.4 KiB
Python
Raw Normal View History

from datetime import datetime, timedelta
2020-01-10 00:01:06 +01:00
import django_tables2 as tables
from core.tables import CoreTable
2020-02-15 18:50:51 +01:00
from .models import ConnectedDevice
2020-01-10 00:01:06 +01:00
from .models import Device
class DevicesTable(CoreTable):
2020-01-10 00:01:06 +01:00
id = tables.Column(visible=False)
name = tables.Column('Device', linkify=True)
class Meta(CoreTable.Meta):
2020-01-10 00:01:06 +01:00
model = Device
2020-02-15 18:50:51 +01:00
class ConnectedDevicesTable(CoreTable):
2020-02-15 18:50:51 +01:00
id = tables.Column(visible=False)
name = tables.Column('ConnectedDevice', linkify=True)
class Meta(CoreTable.Meta):
2020-02-15 18:50:51 +01:00
model = ConnectedDevice
2020-02-16 22:03:43 +01:00
class WarrantiesTable(CoreTable):
customer = tables.Column(linkify=True, orderable=False)
2020-02-16 22:03:43 +01:00
device = tables.Column(linkify=True)
valid_from = tables.Column()
valid_until = tables.Column()
warranty_type = tables.Column()
class Meta(CoreTable.Meta):
pass
def render_valid_until(self, value, column):
today = datetime.date(datetime.today())
2020-02-29 21:08:56 +01:00
one_year_from_today = (datetime.date(datetime.today()
+ timedelta(365)))
if value > one_year_from_today:
column.attrs = {'td': {}}
return value
if value <= today:
column.attrs = {'td': {'bgcolor': 'red'}}
return value
if value <= one_year_from_today:
column.attrs = {'td': {'bgcolor': 'orange'}}
return value