racks.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import django_tables2 as tables
  2. from django_tables2.utils import Accessor
  3. from dcim.models import Rack, RackReservation, RackRole
  4. from tenancy.tables import TenantColumn
  5. from utilities.tables import (
  6. BaseTable, ChoiceFieldColumn, ColorColumn, ColoredLabelColumn, LinkedCountColumn, MarkdownColumn, TagColumn,
  7. ToggleColumn, UtilizationColumn,
  8. )
  9. __all__ = (
  10. 'RackTable',
  11. 'RackReservationTable',
  12. 'RackRoleTable',
  13. )
  14. #
  15. # Rack roles
  16. #
  17. class RackRoleTable(BaseTable):
  18. pk = ToggleColumn()
  19. name = tables.Column(linkify=True)
  20. rack_count = tables.Column(verbose_name='Racks')
  21. color = ColorColumn()
  22. tags = TagColumn(
  23. url_name='dcim:rackrole_list'
  24. )
  25. class Meta(BaseTable.Meta):
  26. model = RackRole
  27. fields = (
  28. 'pk', 'id', 'name', 'rack_count', 'color', 'description', 'slug', 'tags', 'actions', 'created',
  29. 'last_updated',
  30. )
  31. default_columns = ('pk', 'name', 'rack_count', 'color', 'description')
  32. #
  33. # Racks
  34. #
  35. class RackTable(BaseTable):
  36. pk = ToggleColumn()
  37. name = tables.Column(
  38. order_by=('_name',),
  39. linkify=True
  40. )
  41. location = tables.Column(
  42. linkify=True
  43. )
  44. site = tables.Column(
  45. linkify=True
  46. )
  47. tenant = TenantColumn()
  48. status = ChoiceFieldColumn()
  49. role = ColoredLabelColumn()
  50. u_height = tables.TemplateColumn(
  51. template_code="{{ record.u_height }}U",
  52. verbose_name='Height'
  53. )
  54. comments = MarkdownColumn()
  55. device_count = LinkedCountColumn(
  56. viewname='dcim:device_list',
  57. url_params={'rack_id': 'pk'},
  58. verbose_name='Devices'
  59. )
  60. get_utilization = UtilizationColumn(
  61. orderable=False,
  62. verbose_name='Space'
  63. )
  64. get_power_utilization = UtilizationColumn(
  65. orderable=False,
  66. verbose_name='Power'
  67. )
  68. tags = TagColumn(
  69. url_name='dcim:rack_list'
  70. )
  71. outer_width = tables.TemplateColumn(
  72. template_code="{{ record.outer_width }} {{ record.outer_unit }}",
  73. verbose_name='Outer Width'
  74. )
  75. outer_depth = tables.TemplateColumn(
  76. template_code="{{ record.outer_depth }} {{ record.outer_unit }}",
  77. verbose_name='Outer Depth'
  78. )
  79. class Meta(BaseTable.Meta):
  80. model = Rack
  81. fields = (
  82. 'pk', 'id', 'name', 'site', 'location', 'status', 'facility_id', 'tenant', 'role', 'serial', 'asset_tag',
  83. 'type', 'width', 'outer_width', 'outer_depth', 'u_height', 'comments', 'device_count', 'get_utilization',
  84. 'get_power_utilization', 'tags', 'created', 'last_updated',
  85. )
  86. default_columns = (
  87. 'pk', 'name', 'site', 'location', 'status', 'facility_id', 'tenant', 'role', 'u_height', 'device_count',
  88. 'get_utilization',
  89. )
  90. #
  91. # Rack reservations
  92. #
  93. class RackReservationTable(BaseTable):
  94. pk = ToggleColumn()
  95. reservation = tables.Column(
  96. accessor='pk',
  97. linkify=True
  98. )
  99. site = tables.Column(
  100. accessor=Accessor('rack__site'),
  101. linkify=True
  102. )
  103. tenant = TenantColumn()
  104. rack = tables.Column(
  105. linkify=True
  106. )
  107. unit_list = tables.Column(
  108. orderable=False,
  109. verbose_name='Units'
  110. )
  111. tags = TagColumn(
  112. url_name='dcim:rackreservation_list'
  113. )
  114. class Meta(BaseTable.Meta):
  115. model = RackReservation
  116. fields = (
  117. 'pk', 'id', 'reservation', 'site', 'rack', 'unit_list', 'user', 'created', 'tenant', 'description', 'tags',
  118. 'actions', 'created', 'last_updated',
  119. )
  120. default_columns = ('pk', 'reservation', 'site', 'rack', 'unit_list', 'user', 'description')