tables.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. import django_tables2 as tables
  2. from dbsynce.models import *
  3. from webservice_running.models import *
  4. from django.contrib.auth import get_user_model
  5. from django.utils.html import format_html
  6. from django.utils.translation import gettext_lazy as _
  7. from dbsynce.lib.dicts import *
  8. #from webservice_running.lib.dicts import *
  9. class EventTable(tables.Table):
  10. id = tables.Column(
  11. verbose_name=_('ID'),
  12. attrs={
  13. "td": {"width": "5%"}
  14. }
  15. )
  16. title = tables.LinkColumn(
  17. 'sharix_admin:order_detail',
  18. args=[tables.A('pk')],
  19. verbose_name=_('Title'),
  20. attrs={
  21. "td": {"width": "20%"}
  22. }
  23. )
  24. status = tables.Column(
  25. accessor='status',
  26. #accessor='status_by_code(status)',
  27. verbose_name=_('Status'),
  28. attrs={
  29. "td": {"width": "15%"}
  30. }
  31. )
  32. receiver = tables.Column(
  33. accessor='receiver.get_full_name',
  34. verbose_name=_('Receiver'),
  35. #'sharix_admin:user_detail',
  36. #args=[tables.A('pk')],
  37. attrs={
  38. "td": {"width": "20%"}
  39. }
  40. )
  41. time_created = tables.DateTimeColumn(
  42. verbose_name=_('Created'),
  43. attrs={
  44. "td": {"width": "20%"}
  45. }
  46. )
  47. class Meta:
  48. model = Orders
  49. attrs = {
  50. "class": "table table-layout-fixed"
  51. }
  52. exclude = (
  53. 'id_metaservice',
  54. 'note',
  55. 'time_placed',
  56. 'time_start',
  57. 'time_start_real',
  58. 'time_start_predicted',
  59. 'time_finish_real',
  60. 'time_finish_predicted',
  61. 'real_price',
  62. 'predicted_price',
  63. 'asap',
  64. 'is_global',
  65. 'is_visible',
  66. 'ticket',
  67. 'service',
  68. 'service_category',
  69. 'client',
  70. 'provider',
  71. 'company')
  72. class PlaceTable(tables.Table):
  73. id = tables.LinkColumn(
  74. 'sharix_admin:resource_detail',
  75. args=[tables.A('pk')],
  76. verbose_name=_('ID'),
  77. attrs={
  78. "td": {"width": "5%"}
  79. }
  80. )
  81. # В user ссылка LinkColumn на страницу Аси "Информация о партнере" страница partner_information_form
  82. user = tables.Column(
  83. accessor='user.get_full_name',
  84. order_by=('user.first_name', 'user.last_name'),
  85. verbose_name=_('Responsible'),
  86. attrs={
  87. "td": {"width": "15%"}
  88. }
  89. )
  90. status = tables.Column(
  91. verbose_name=_('Status'),
  92. attrs={
  93. 'th': {'scope': 'col'},
  94. "td": {"width": "20%"}
  95. }
  96. )
  97. resource_type = tables.Column(
  98. attrs={
  99. 'th': {'scope': 'col'},
  100. "td": {"width": "20%"}
  101. }
  102. )
  103. edit = tables.LinkColumn(
  104. 'sharix_admin:resource/edit/',
  105. verbose_name='',
  106. orderable=False,
  107. text="E",
  108. args=[tables.A('pk')],
  109. attrs={
  110. 'th': {'scope': 'col'},
  111. "td": {"class": "edit_col"},
  112. "td": {"width": "10%"}
  113. }
  114. )
  115. check = tables.BooleanColumn(
  116. verbose_name='',
  117. attrs={
  118. 'th': {'scope': 'col'},
  119. "td": {"width": "10%"}
  120. }
  121. )
  122. # paginate_by = 10
  123. class Meta:
  124. model = Resource
  125. attrs = {
  126. "class": "table table-layout-fixed"
  127. }
  128. exclude = (
  129. 'id_metaservice',
  130. 'requirements',
  131. 'is_global',
  132. 'is_visible',
  133. 'ticket_status'
  134. )
  135. def render_check(self, value, record):
  136. if record.status == 'active':
  137. return format_html(
  138. '<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-resource-id="{}">',
  139. record.id
  140. )
  141. else:
  142. return format_html(
  143. '<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-resource-id="{}">',
  144. record.id
  145. )