tables.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. import django_tables2 as tables
  2. from dbsynce.models import *
  3. from dbsynce.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 sharix_admin.tables import ShariXTable
  9. class ProvidersLandingTable(ShariXTable):
  10. id = tables.Column(
  11. verbose_name=_('ID'),
  12. attrs={
  13. "td": {"width": "5%"}
  14. }
  15. )
  16. gap = tables.Column(
  17. #verbose_name=_('Status'),
  18. attrs={
  19. 'th': {'scope': 'col'},
  20. "td": {"width": "20%"}
  21. }
  22. )
  23. service_status = tables.Column(
  24. attrs={
  25. 'th': {'scope': 'col'},
  26. "td": {"width": "20%"}
  27. }
  28. )
  29. default_location = tables.Column(
  30. attrs={
  31. 'th': {'scope': 'col'},
  32. "td": {"width": "20%"}
  33. }
  34. )
  35. service = tables.LinkColumn(
  36. 'sharix_admin:service_tariff_detail',
  37. args=[tables.A('service.pk')],
  38. accessor='service.caption',
  39. verbose_name=_('Service'),
  40. attrs={'th': {'scope': 'col'}, "td": {"width": "20%"}}
  41. )
  42. resource = tables.LinkColumn(
  43. 'sharix_admin:resource_detail',
  44. args=[tables.A('resource.pk')],
  45. accessor='resource.resource_type',
  46. verbose_name=_('Resource'),
  47. attrs={
  48. 'th': {'scope': 'col'},
  49. "td": {"width": "20%"}
  50. }
  51. )
  52. class Meta:
  53. model = Provider
  54. attrs = {
  55. "class": "table table-layout-fixed"
  56. }
  57. exclude = (
  58. 'id_metaservice',
  59. 'requirements',
  60. 'status',
  61. 'location_type',
  62. 'default_location',
  63. 'is_global',
  64. 'is_visible',
  65. 'ticket_status',
  66. )
  67. class ServiceCategoryLandingTable(ShariXTable):
  68. caption = tables.LinkColumn(
  69. 'landing_service_detail',
  70. args=[tables.A('pk')],
  71. text=lambda record: record.caption,
  72. verbose_name=_('Название'),
  73. attrs={
  74. 'th': {'scope': 'col'},
  75. 'td': {'class': 'name_col'},
  76. }
  77. )
  78. price_min = tables.Column(
  79. verbose_name=_('Цена за минуту'),
  80. attrs={
  81. 'th': {'scope': 'col'},
  82. 'td': {'width': '18%'},
  83. }
  84. )
  85. price_amount = tables.Column(
  86. verbose_name=_('Фиксированная цена'),
  87. attrs={
  88. 'th': {'scope': 'col'},
  89. 'td': {'width': '18%'},
  90. }
  91. )
  92. price_km = tables.Column(
  93. verbose_name=_('Цена за км'),
  94. attrs={
  95. 'th': {'scope': 'col'},
  96. 'td': {'width': '18%'},
  97. }
  98. )
  99. def render_price_min(self, value):
  100. return value if value not in (None, '') else '—'
  101. def render_price_amount(self, value):
  102. return value if value not in (None, '') else '—'
  103. def render_price_km(self, value):
  104. return value if value not in (None, '') else '—'
  105. class Meta:
  106. model = Service
  107. attrs = {
  108. "class": "table table-layout-fixed text-start"
  109. }
  110. fields = (
  111. 'caption',
  112. 'price_min',
  113. 'price_amount',
  114. 'price_km',
  115. )
  116. class ServiceCategoryLandingTable(ShariXTable):
  117. caption = tables.LinkColumn(
  118. 'landing_service_detail',
  119. args=[tables.A('pk')],
  120. text=lambda record: record.caption,
  121. verbose_name=_('Название'),
  122. attrs={
  123. 'th': {'scope': 'col'},
  124. 'td': {'class': 'name_col'},
  125. }
  126. )
  127. price_min = tables.Column(
  128. verbose_name=_('Цена за минуту'),
  129. attrs={
  130. 'th': {'scope': 'col'},
  131. 'td': {'width': '18%'},
  132. }
  133. )
  134. price_amount = tables.Column(
  135. verbose_name=_('Фиксированная цена'),
  136. attrs={
  137. 'th': {'scope': 'col'},
  138. 'td': {'width': '18%'},
  139. }
  140. )
  141. price_km = tables.Column(
  142. verbose_name=_('Цена за км'),
  143. attrs={
  144. 'th': {'scope': 'col'},
  145. 'td': {'width': '18%'},
  146. }
  147. )
  148. def render_price_min(self, value):
  149. return value if value not in (None, '') else '—'
  150. def render_price_amount(self, value):
  151. return value if value not in (None, '') else '—'
  152. def render_price_km(self, value):
  153. return value if value not in (None, '') else '—'
  154. class Meta:
  155. model = Service
  156. attrs = {
  157. "class": "table table-layout-fixed text-start"
  158. }
  159. fields = (
  160. 'caption',
  161. 'price_min',
  162. 'price_amount',
  163. 'price_km',
  164. )