Coverage for extras/tables/columns.py: 80%

15 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-10 18:35 +0000

1import django_tables2 as tables 

2from django.utils.html import format_html 

3from django.utils.translation import gettext as _ 

4 

5from extras.choices import CustomFieldStatusChoices 

6from netbox.tables.columns import ActionsColumn, ActionsItem 

7 

8__all__ = ( 

9 'CustomFieldStatusColumn', 

10 'NotificationActionsColumn', 

11) 

12 

13 

14class CustomFieldStatusColumn(tables.Column): 

15 """ 

16 Render a custom field's status as an icon: a checkmark where the field is live, and a warning 

17 where a bulk update of its stored data is still pending (see CustomFieldStatusChoices). 

18 

19 An icon because the status is worth noting only in the exceptional case, which is any state 

20 other than active. The full label is given as hover text, and is what an export records. 

21 """ 

22 ICONS = { 

23 True: ('text-bg-green', 'mdi-check-bold'), 

24 False: ('text-bg-orange', 'mdi-alert'), 

25 } 

26 

27 def render(self, record): 

28 css_class, icon = self.ICONS[record.status == CustomFieldStatusChoices.STATUS_ACTIVE] 

29 return format_html( 

30 '<span class="badge {}" title="{}"><i class="mdi {}"></i></span>', 

31 css_class, record.get_status_display(), icon 

32 ) 

33 

34 def value(self, record): 

35 return record.get_status_display() 

36 

37 

38class NotificationActionsColumn(ActionsColumn): 

39 actions = { 

40 'dismiss': ActionsItem(_('Dismiss'), 'trash-can-outline', 'delete', 'danger'), 

41 }