Coverage for ipam/tables/services.py: 100%

23 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.translation import gettext_lazy as _ 

3 

4from ipam.models import * 

5from netbox.tables import PrimaryModelTable, columns 

6from tenancy.tables import ContactsColumnMixin 

7 

8__all__ = ( 

9 'ServiceTable', 

10 'ServiceTemplateTable', 

11) 

12 

13 

14class ServiceTemplateTable(PrimaryModelTable): 

15 name = tables.Column( 

16 verbose_name=_('Name'), 

17 linkify=True 

18 ) 

19 # Column key kept as 'ports' (not renamed to 'port_mappings') so existing saved table configs keep 

20 # working; the removed single 'protocol' column, however, will silently drop out of any saved config 

21 # or export template that referenced it. 

22 ports = tables.Column( 

23 verbose_name=_('Port Mappings'), 

24 accessor=tables.A('port_mappings_list'), 

25 orderable=False, 

26 ) 

27 tags = columns.TagColumn( 

28 url_name='ipam:servicetemplate_list' 

29 ) 

30 

31 class Meta(PrimaryModelTable.Meta): 

32 model = ServiceTemplate 

33 fields = ( 

34 'pk', 'id', 'name', 'ports', 'description', 'comments', 'tags', 'created', 'last_updated', 

35 ) 

36 default_columns = ('pk', 'name', 'ports', 'description') 

37 

38 

39class ServiceTable(ContactsColumnMixin, PrimaryModelTable): 

40 name = tables.Column( 

41 verbose_name=_('Name'), 

42 linkify=True 

43 ) 

44 parent = tables.Column( 

45 verbose_name=_('Parent'), 

46 linkify=True, 

47 order_by=('device', 'virtual_machine') 

48 ) 

49 # Column key kept as 'ports' (not renamed to 'port_mappings') so existing saved table configs keep 

50 # working; the removed single 'protocol' column, however, will silently drop out of any saved config 

51 # or export template that referenced it. 

52 ports = tables.Column( 

53 verbose_name=_('Port Mappings'), 

54 accessor=tables.A('port_mappings_list'), 

55 orderable=False, 

56 ) 

57 tags = columns.TagColumn( 

58 url_name='ipam:service_list' 

59 ) 

60 

61 class Meta(PrimaryModelTable.Meta): 

62 model = Service 

63 fields = ( 

64 'pk', 'id', 'name', 'parent', 'ports', 'ipaddresses', 'description', 'contacts', 'comments', 

65 'tags', 'created', 'last_updated', 

66 ) 

67 default_columns = ('pk', 'name', 'parent', 'ports', 'description')