modules.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import django_tables2 as tables
  2. from dcim.models import Module, ModuleType
  3. from netbox.tables import NetBoxTable, columns
  4. from .template_code import DEVICE_WEIGHT
  5. __all__ = (
  6. 'ModuleTable',
  7. 'ModuleTypeTable',
  8. )
  9. class ModuleTypeTable(NetBoxTable):
  10. model = tables.Column(
  11. linkify=True,
  12. verbose_name='Module Type'
  13. )
  14. manufacturer = tables.Column(
  15. linkify=True
  16. )
  17. instance_count = columns.LinkedCountColumn(
  18. viewname='dcim:module_list',
  19. url_params={'module_type_id': 'pk'},
  20. verbose_name='Instances'
  21. )
  22. comments = columns.MarkdownColumn()
  23. tags = columns.TagColumn(
  24. url_name='dcim:moduletype_list'
  25. )
  26. weight = columns.TemplateColumn(
  27. template_code=DEVICE_WEIGHT,
  28. order_by=('_abs_weight', 'weight_unit')
  29. )
  30. class Meta(NetBoxTable.Meta):
  31. model = ModuleType
  32. fields = (
  33. 'pk', 'id', 'model', 'manufacturer', 'part_number', 'weight', 'description', 'comments', 'tags',
  34. )
  35. default_columns = (
  36. 'pk', 'model', 'manufacturer', 'part_number',
  37. )
  38. class ModuleTable(NetBoxTable):
  39. device = tables.Column(
  40. linkify=True
  41. )
  42. module_bay = tables.Column(
  43. linkify=True
  44. )
  45. manufacturer = tables.Column(
  46. accessor=tables.A('module_type__manufacturer'),
  47. linkify=True
  48. )
  49. module_type = tables.Column(
  50. linkify=True
  51. )
  52. comments = columns.MarkdownColumn()
  53. tags = columns.TagColumn(
  54. url_name='dcim:module_list'
  55. )
  56. class Meta(NetBoxTable.Meta):
  57. model = Module
  58. fields = (
  59. 'pk', 'id', 'device', 'module_bay', 'manufacturer', 'module_type', 'serial', 'asset_tag', 'description',
  60. 'comments', 'tags',
  61. )
  62. default_columns = (
  63. 'pk', 'id', 'device', 'module_bay', 'manufacturer', 'module_type', 'serial', 'asset_tag',
  64. )