2023-10-24 11:35:53 -04:00
|
|
|
import django_tables2 as tables
|
2024-02-01 08:44:07 -08:00
|
|
|
from django.utils.safestring import mark_safe
|
2023-10-24 11:35:53 -04:00
|
|
|
|
2024-02-01 08:44:07 -08:00
|
|
|
from core.constants import RQ_TASK_STATUSES
|
2023-10-24 11:35:53 -04:00
|
|
|
from netbox.registry import registry
|
|
|
|
|
|
|
|
__all__ = (
|
|
|
|
'BackendTypeColumn',
|
2024-02-01 08:44:07 -08:00
|
|
|
'RQJobStatusColumn',
|
2023-10-24 11:35:53 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class BackendTypeColumn(tables.Column):
|
|
|
|
"""
|
|
|
|
Display a data backend type.
|
|
|
|
"""
|
|
|
|
def render(self, value):
|
|
|
|
if backend := registry['data_backends'].get(value):
|
|
|
|
return backend.label
|
|
|
|
return value
|
|
|
|
|
|
|
|
def value(self, value):
|
|
|
|
return value
|
2024-02-01 08:44:07 -08:00
|
|
|
|
|
|
|
|
|
|
|
class RQJobStatusColumn(tables.Column):
|
|
|
|
"""
|
|
|
|
Render a colored label for the status of an RQ job.
|
|
|
|
"""
|
|
|
|
def render(self, value):
|
|
|
|
status = RQ_TASK_STATUSES.get(value)
|
|
|
|
return mark_safe(f'<span class="badge text-bg-{status.color}">{status.label}</span>')
|
|
|
|
|
|
|
|
def value(self, value):
|
|
|
|
status = RQ_TASK_STATUSES.get(value)
|
|
|
|
return status.label
|