tables.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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. class TransactionsWalletTable(tables.Table):
  8. # id = tables.Column(order_by=True)
  9. id = tables.Column(verbose_name='#', orderable=False, attrs={"td": {"width": "5%"}})
  10. wallet = tables.Column(verbose_name=_('Owner'), orderable=False, attrs={"td": {"width": "15%"}})
  11. name_operation = tables.Column(verbose_name=_('Service'), attrs={'th': {'scope': 'col'}, "td": {"width": "20%"}})
  12. price = tables.Column(verbose_name=_('Points'), attrs={"class": "row", "td": {"width": "10%"}})
  13. date_operation = tables.Column(verbose_name=_('Registration date'), attrs={"td": {"width": "30%"}})
  14. is_carried_out = tables.BooleanColumn(verbose_name=_('Status'), orderable=False,
  15. yesno=_("Successful, not successful"), attrs={"td": {"width": "20%"}})
  16. class Meta:
  17. # model = TransactionsWallets
  18. attrs = {"class": "table table-striped"}
  19. exclude = (
  20. "balance_before",
  21. "amount",
  22. "metaservice_id",
  23. "transaction_type",
  24. "doc_num",
  25. "service_id"
  26. )
  27. def render_name_operation(self, value, record):
  28. return format_html("<a href='{}'>{}</a>", record.get_absolute_url(), value)
  29. class PartnersTable(tables.Table):
  30. id = tables.Column(verbose_name=_('ID'), attrs={"td": {"width": "5%"}})
  31. legal_name = tables.Column(verbose_name=_('Legal entity'), attrs={'th': {'scope': 'col'}, "td": {"width": "20%"}})
  32. repr_id = tables.Column(accessor='repr_id.full_name', order_by=('repr_id.first_name', 'repr_id.last_name'),
  33. verbose_name=_('Responsible'), attrs={"td": {"width": "15%"}})
  34. status = tables.Column(verbose_name=_('Status'), attrs={'th': {'scope': 'col'}, "td": {"width": "20%"}})
  35. check = tables.BooleanColumn(verbose_name='', attrs={'th': {'scope': 'col'}, "td": {"width": "20%"}})
  36. # paginate_by = 10
  37. class Meta:
  38. model = Company
  39. attrs = {
  40. "class": "table table-layout-fixed"
  41. }
  42. exclude = (
  43. 'inn',
  44. 'kpp',
  45. 'ogrn',
  46. 'bank_name',
  47. 'bik',
  48. 'ks',
  49. 'rs',
  50. 'address',
  51. 'requirements',
  52. 'id_metaservice',
  53. 'is_global',
  54. 'is_visible',
  55. 'ticket_status'
  56. )
  57. def render_check(self, value, record):
  58. if record.status == 'active':
  59. return format_html(
  60. '<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-partners-id="{}">',
  61. record.id)
  62. else:
  63. return format_html(
  64. '<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-partners-id="{}">',
  65. record.id)
  66. class ResourceTable(tables.Table):
  67. id = tables.Column(verbose_name=_('ID'), attrs={"td": {"width": "5%"}})
  68. # В user_id ссылка LinkColumn на страницу Аси "Информация о партнере" страница partner_information_form
  69. user_id = tables.Column(accessor='user_id.full_name', order_by=('user_id.first_name', 'user_id.last_name'),
  70. verbose_name=_('Responsible'), attrs={"td": {"width": "15%"}})
  71. status = tables.Column(verbose_name=_('Status'), attrs={'th': {'scope': 'col'}, "td": {"width": "20%"}})
  72. check = tables.BooleanColumn(verbose_name='', attrs={'th': {'scope': 'col'}, "td": {"width": "20%"}})
  73. # paginate_by = 10
  74. class Meta:
  75. model = Resource
  76. attrs = {"class": "table table-layout-fixed"}
  77. exclude = (
  78. 'id_metaservice',
  79. 'resoure_type',
  80. 'requirements',
  81. 'is_global',
  82. 'is_visible',
  83. 'ticket_status'
  84. )
  85. def render_check(self, value, record):
  86. if record.status == 'active':
  87. return format_html(
  88. '<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-resource-id="{}">',
  89. record.id)
  90. else:
  91. return format_html(
  92. '<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-resource-id="{}">',
  93. record.id)
  94. class ProviderTable(tables.Table):
  95. id = tables.Column(verbose_name=_('ID'), attrs={"td": {"width": "5%"}})
  96. user_id = tables.Column(accessor='user_id.full_name', order_by=('user_id.first_name', 'user_id.last_name'),
  97. verbose_name=_('Full Name'), attrs={"td": {"width": "15%"}})
  98. status = tables.Column(verbose_name=_('Status'), attrs={'th': {'scope': 'col'}, "td": {"width": "20%"}})
  99. check = tables.BooleanColumn(verbose_name='', attrs={'th': {'scope': 'col'}, "td": {"width": "20%"}})
  100. paginate_by = 10
  101. class Meta:
  102. model = Provider
  103. attrs = {"class": "table table-layout-fixed"}
  104. exclude = ('type', 'company_id', 'id_metaservice', 'requirements',
  105. 'ticket_status', 'location_type', 'default_location',
  106. 'is_global', 'is_visible')
  107. def render_check(self, value, record):
  108. if record.status == 'active':
  109. return format_html(
  110. '<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-provider-id="{}">',
  111. record.id)
  112. else:
  113. return format_html(
  114. '<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-provider-id="{}">',
  115. record.id)
  116. class ServiceTariffTable(tables.Table):
  117. id = tables.Column(verbose_name=_('ID'), attrs={"td": {"width": "5%"}})
  118. servicetype_id = tables.LinkColumn('service_tariff/edit/', verbose_name=_('Name of the tariff'),
  119. text=lambda record: record.servicetype_id.caption,
  120. args=[tables.A('pk')], attrs={'th': {'scope': 'col'}, "td": {"width": "20%"}})
  121. ticket_status = tables.Column(verbose_name=_('Name of the service scheme'),
  122. attrs={'th': {'scope': 'col'}, "td": {"width": "20%"}})
  123. check = tables.BooleanColumn(verbose_name=_('Activity'), orderable=False,
  124. attrs={'th': {'scope': 'col'}, "td": {"width": "20%"}})
  125. class Meta:
  126. model = Service
  127. attrs = {"class": "table table-layout-fixed"}
  128. exclude = (
  129. 'resource_id',
  130. 'price_alg',
  131. 'price_min',
  132. 'price_amount',
  133. 'id_metaservice',
  134. 'requirements',
  135. 'service_status',
  136. 'price_km',
  137. 'is_global',
  138. 'is_visible',
  139. 'status'
  140. )
  141. def render_check(self, value, record):
  142. if record.status == 'active':
  143. return format_html('<input class="form-check-input status-toggle" disabled checked type="checkbox"')
  144. else:
  145. return format_html('<input class="form-check-input status-toggle" disabled type="checkbox"')
  146. class ServiceTypeTable(tables.Table):
  147. id = tables.Column(attrs={"td": {"width": "50px"}})
  148. codename = tables.LinkColumn('service_type/edit/', verbose_name='Услуга', orderable=False,
  149. text=lambda record: record.codename,
  150. args=[tables.A('pk')],
  151. attrs={"a": {"style": "pointer-events: none;"}, 'th': {'scope': 'col'},
  152. "td": {"class": "name_col"}})
  153. description = tables.LinkColumn('service_type/edit/', orderable=False, verbose_name='Описание',
  154. text=lambda record: record.description,
  155. args=[tables.A('pk')],
  156. attrs={"a": {"style": "pointer-events: none;"}, 'th': {'scope': 'col'},
  157. "td": {"class": "description_col"}})
  158. edit = tables.LinkColumn('service_type/edit/', verbose_name='', orderable=False, text="E",
  159. args=[tables.A('pk')], attrs={'th': {'scope': 'col'}, "td": {"class": "edit_col"}})
  160. deletee = tables.LinkColumn('service_type/delete/', verbose_name='', orderable=False, text="D",
  161. args=[tables.A('pk')], attrs={'th': {'scope': 'col'}, "td": {"class": "delete_col"}})
  162. class Meta:
  163. model = ServiceType
  164. attrs = {"class": "table table-layout-fixed text-start"}
  165. exclude = ('requirements',
  166. 'price_type', 'status', 'ticket_status',
  167. 'id_metaservice', 'link_agreement',
  168. 'is_global', 'is_visible', 'caption')
  169. # def render_delete(self, value, record):
  170. # return format_html('<a href="/service_type/delete" class="btn btn-outline-danger">_(Delete)</a>')
  171. # def render_name_operation(self, value, record):
  172. # return format_html("<a href='{}'>{}</a>", record.get_absolute_url(), value)
  173. class ServiceTable(tables.Table):
  174. id = tables.Column(verbose_name=_('ID'), attrs={"td": {"width": "5%"}})
  175. servicetype_id = tables.Column(verbose_name=_('Description of the service'), accessor='servicetype_id.caption',
  176. attrs={'th': {'scope': 'col'}, "td": {"width": "20%"}})
  177. # description = tables.Column(verbose_name='Название тарифа', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  178. # description = tables.Column(verbose_name='Описание строки тарифов', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  179. # price_type = tables.Column(verbose_name='Тип тарифа', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  180. price_km = tables.Column(verbose_name=_('Cost km.'), attrs={'th': {'scope': 'col'}, "td": {"width": "20%"}})
  181. price_min = tables.Column(verbose_name=_('Cost min.'), attrs={'th': {'scope': 'col'}, "td": {"width": "20%"}})
  182. price_amount = tables.Column(verbose_name=_('Cost of service'),
  183. attrs={'th': {'scope': 'col'}, "td": {"width": "20%"}})
  184. class Meta:
  185. model = Service
  186. attrs = {"class": "table table-layout-fixed"}
  187. exclude = (
  188. 'resource_id',
  189. 'requirements',
  190. 'id_metaservice',
  191. 'price_alg',
  192. 'service_status',
  193. 'ticket_status',
  194. 'is_global',
  195. 'is_visible'
  196. )
  197. def render_check(self, value, record):
  198. if record.status == 'active':
  199. return format_html(
  200. '<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-service-id="{}">',
  201. record.id)
  202. else:
  203. return format_html(
  204. '<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-service-id="{}">',
  205. record.id)
  206. class UserInfoTable(tables.Table):
  207. id = tables.Column(verbose_name=_('ID'), attrs={"td": {"width": "5%"}})
  208. class Meta:
  209. model = get_user_model()
  210. attrs = {"class": "table table-layout-fixed"}
  211. exclude = ('password', 'phone_number',
  212. 'last_login', 'is_staff', 'is_superuser',
  213. 'date_joined')