cables.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import django_tables2 as tables
  2. from django_tables2.utils import Accessor
  3. from dcim.models import Cable
  4. from utilities.tables import BaseTable, ChoiceFieldColumn, ColorColumn, TagColumn, ToggleColumn
  5. from .template_code import CABLE_LENGTH, CABLE_TERMINATION_PARENT
  6. __all__ = (
  7. 'CableTable',
  8. )
  9. #
  10. # Cables
  11. #
  12. class CableTable(BaseTable):
  13. pk = ToggleColumn()
  14. id = tables.Column(
  15. linkify=True,
  16. verbose_name='ID'
  17. )
  18. termination_a_parent = tables.TemplateColumn(
  19. template_code=CABLE_TERMINATION_PARENT,
  20. accessor=Accessor('termination_a'),
  21. orderable=False,
  22. verbose_name='Side A'
  23. )
  24. termination_a = tables.Column(
  25. accessor=Accessor('termination_a'),
  26. orderable=False,
  27. linkify=True,
  28. verbose_name='Termination A'
  29. )
  30. termination_b_parent = tables.TemplateColumn(
  31. template_code=CABLE_TERMINATION_PARENT,
  32. accessor=Accessor('termination_b'),
  33. orderable=False,
  34. verbose_name='Side B'
  35. )
  36. termination_b = tables.Column(
  37. accessor=Accessor('termination_b'),
  38. orderable=False,
  39. linkify=True,
  40. verbose_name='Termination B'
  41. )
  42. status = ChoiceFieldColumn()
  43. length = tables.TemplateColumn(
  44. template_code=CABLE_LENGTH,
  45. order_by='_abs_length'
  46. )
  47. color = ColorColumn()
  48. tags = TagColumn(
  49. url_name='dcim:cable_list'
  50. )
  51. class Meta(BaseTable.Meta):
  52. model = Cable
  53. fields = (
  54. 'pk', 'id', 'label', 'termination_a_parent', 'termination_a', 'termination_b_parent', 'termination_b',
  55. 'status', 'type', 'color', 'length', 'tags',
  56. )
  57. default_columns = (
  58. 'pk', 'id', 'label', 'termination_a_parent', 'termination_a', 'termination_b_parent', 'termination_b',
  59. 'status', 'type',
  60. )