tables.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. import django_tables2 as tables
  2. from metaservicesynced.models import *
  3. from .models import *
  4. from django.utils.html import format_html
  5. from django.http import HttpResponse
  6. from metaservicesynced.models import *
  7. class CooperationTable(tables.Table):
  8. id = tables.Column(verbose_name='ID', attrs={"td":{"width":"5%"}})
  9. legal_name = tables.Column(verbose_name='Юрлицо', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  10. repr_id = tables.Column(accessor='repr_id.full_name', order_by=('repr_id.first_name', 'repr_id.last_name'), verbose_name='Ответственный', attrs={"td":{"width":"15%"}})
  11. status = tables.Column(verbose_name='Статус', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  12. check = tables.BooleanColumn(verbose_name='', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  13. # paginate_by = 10
  14. class Meta:
  15. model = Company
  16. attrs = {"class": "table table-layout-fixed"}
  17. exclude = ('inn','kpp','ogrn', 'bank_name',
  18. 'bik', 'ks', 'rs',
  19. 'address', 'requirements',
  20. 'id_metaservice', 'is_global', 'is_visible', 'ticket_status')
  21. def render_check(self, value, record):
  22. if record.status == 'active':
  23. return format_html('<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-partners-id="{}">', record.id)
  24. else:
  25. return format_html('<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-partners-id="{}">', record.id)
  26. class become_partnerTable(tables.Table):
  27. id = tables.Column(verbose_name='айди', attrs={"td":{"width":"20%"}})
  28. legal_name = tables.Column(verbose_name='айди', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  29. repr_id = tables.Column(accessor='repr_id.full_name', order_by=('repr_id.first_name', 'repr_id.last_name'), verbose_name='стать партнером', attrs={"td":{"width":"15%"}})
  30. status = tables.Column(verbose_name='Статус', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  31. check = tables.BooleanColumn(verbose_name='', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  32. # paginate_by = 10
  33. class Meta:
  34. model = Company
  35. attrs = {"class": "table table-layout-fixed"}
  36. exclude = ('inn','kpp','ogrn', 'bank_name',
  37. 'bik', 'ks', 'rs',
  38. 'address', 'requirements',
  39. 'id_metaservice', 'is_global', 'is_visible', 'ticket_status')
  40. def render_check(self, value, record):
  41. if record.status == 'active':
  42. return format_html('<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-partners-id="{}">', record.id)
  43. else:
  44. return format_html('<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-partners-id="{}">', record.id)
  45. class TransactionsWalletTable(tables.Table):
  46. # id = tables.Column(order_by=True)
  47. id = tables.Column(verbose_name='#', orderable=False, attrs={"td":{"width":"5%"}})
  48. wallet = tables.Column(verbose_name='Владелец', orderable=False, attrs={"td":{"width":"15%"}})
  49. name_operation = tables.Column(verbose_name='Услуга', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  50. price = tables.Column(verbose_name='Баллы', attrs={"class":"row", "td":{"width":"10%"}})
  51. date_operation = tables.Column(verbose_name='Дата оформления', attrs={"td":{"width":"30%"}})
  52. is_carried_out = tables.BooleanColumn(verbose_name='Статус', orderable=False, yesno="Успешно,Не успешно", attrs={"td":{"width":"20%"}})
  53. class Meta:
  54. #model = TransactionsWallets
  55. attrs = {"class": "table table-striped"}
  56. exclude = ("balance_before",
  57. "amount",
  58. "metaservice_id",
  59. "transaction_type",
  60. "doc_num",
  61. "service_id")
  62. def render_name_operation(self, value, record):
  63. return format_html("<a href='{}'>{}</a>", record.get_absolute_url(), value)
  64. class PartnersTable(tables.Table):
  65. id = tables.Column(verbose_name='ID', attrs={"td":{"width":"5%"}})
  66. legal_name = tables.Column(verbose_name='Юрлицо', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  67. repr_id = tables.Column(accessor='repr_id.full_name', order_by=('repr_id.first_name', 'repr_id.last_name'), verbose_name='Ответственный', attrs={"td":{"width":"15%"}})
  68. status = tables.Column(verbose_name='Статус', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  69. check = tables.BooleanColumn(verbose_name='', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  70. # paginate_by = 10
  71. class Meta:
  72. model = Company
  73. attrs = {"class": "table table-layout-fixed"}
  74. exclude = ('inn','kpp','ogrn', 'bank_name',
  75. 'bik', 'ks', 'rs',
  76. 'address', 'requirements',
  77. 'id_metaservice', 'is_global', 'is_visible', 'ticket_status')
  78. def render_check(self, value, record):
  79. if record.status == 'active':
  80. return format_html('<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-partners-id="{}">', record.id)
  81. else:
  82. return format_html('<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-partners-id="{}">', record.id)
  83. class ResourceTable(tables.Table):
  84. id = tables.Column(verbose_name='ID', attrs={"td":{"width":"5%"}})
  85. #В user_id ссылка LinkColumn на страницу Аси "Информация о партнере" страница partner_information_form
  86. user_id = tables.Column(accessor='user_id.full_name', order_by=('user_id.first_name', 'user_id.last_name'), verbose_name='Ответственный', attrs={"td":{"width":"15%"}})
  87. status = tables.Column(verbose_name='Статус', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  88. check = tables.BooleanColumn(verbose_name='', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  89. # paginate_by = 10
  90. class Meta:
  91. model = Resource
  92. attrs = {"class": "table table-layout-fixed"}
  93. exclude = ('type_id','requirements','ticket_status', 'id_metaservice',
  94. 'is_global', 'is_visible')
  95. def render_check(self, value, record):
  96. if record.status == 'active':
  97. return format_html('<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-resource-id="{}">', record.id)
  98. else:
  99. return format_html('<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-resource-id="{}">', record.id)
  100. class ProviderTable(tables.Table):
  101. id = tables.Column(verbose_name='ID', attrs={"td":{"width":"5%"}})
  102. user_id = tables.Column(accessor='user_id.full_name', order_by=('user_id.first_name', 'user_id.last_name'), verbose_name='ФИО', attrs={"td":{"width":"15%"}})
  103. status = tables.Column(verbose_name='Статус', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  104. check = tables.BooleanColumn(verbose_name='', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  105. paginate_by = 10
  106. class Meta:
  107. model = Provider
  108. attrs = {"class": "table table-layout-fixed"}
  109. exclude = ('type','company_id','id_metaservice', 'requirements',
  110. 'ticket_status', 'location_type', 'default_location',
  111. 'is_global', 'is_visible')
  112. def render_check(self, value, record):
  113. if record.status == 'active':
  114. return format_html('<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-provider-id="{}">', record.id)
  115. else:
  116. return format_html('<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-provider-id="{}">', record.id)
  117. class ServiceTariffTable(tables.Table):
  118. id = tables.Column(verbose_name='ID', attrs={"td":{"width":"5%"}})
  119. servicetype_id = tables.LinkColumn('service_tariff/edit/', verbose_name='Название тарифа', 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='Название схемы услуги', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  122. check = tables.BooleanColumn(verbose_name='Активность', orderable=False, attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  123. class Meta:
  124. model = Service
  125. attrs = {"class": "table table-layout-fixed"}
  126. exclude = ('resource_id','id_provider','price_alg',
  127. 'price_min','price_amount','id_metaservice',
  128. 'requirements', 'service_status', 'price_km',
  129. 'is_global', 'is_visible','status')
  130. def render_check(self, value, record):
  131. if record.status == 'active':
  132. return format_html('<input class="form-check-input status-toggle" disabled checked type="checkbox"')
  133. else:
  134. return format_html('<input class="form-check-input status-toggle" disabled type="checkbox"')
  135. class ServiceTypeTable(tables.Table):
  136. id = tables.Column(verbose_name='ID', attrs={"td":{"width":"5%"}})
  137. caption = tables.LinkColumn('service_type/edit/', verbose_name='Название услуги', text = lambda record: record.caption,
  138. args=[tables.A('pk')], attrs={'th':{'scope':'col'}, "td":{"width":"100%"},})
  139. deletee = tables.LinkColumn('service_type/delete/', verbose_name='', text = "Удалить",
  140. args=[tables.A('pk')], attrs={'th':{'scope':'col'}, "td":{"width":"auto"},})
  141. class Meta:
  142. model = ServiceType
  143. attrs = {"class": "table table-layout-fixed text-start"}
  144. exclude = ('codename','description','requirements',
  145. 'price_type','status','ticket_status',
  146. 'id_metaservice', 'link_agreement',
  147. 'is_global', 'is_visible',)
  148. def render_delete(self, value, record):
  149. return format_html('<a href="/service_type/delete" class="btn btn-outline-danger">Удалить</a>')
  150. def render_name_operation(self, value, record):
  151. return format_html("<a href='{}'>{}</a>", record.get_absolute_url(), value)
  152. class ServiceTable(tables.Table):
  153. id = tables.Column(verbose_name='ID', attrs={"td":{"width":"5%"}})
  154. servicetype_id = tables.Column(verbose_name='Описание услуги (сервиса)', accessor = 'servicetype_id.caption',
  155. attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  156. # description = tables.Column(verbose_name='Название тарифа', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  157. # description = tables.Column(verbose_name='Описание строки тарифов', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  158. # price_type = tables.Column(verbose_name='Тип тарифа', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  159. price_km = tables.Column(verbose_name='Стоимость км.', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  160. price_min = tables.Column(verbose_name='Стоимость мин.', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  161. price_amount = tables.Column(verbose_name='Стоимость услуги', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  162. class Meta:
  163. model = Service
  164. attrs = {"class": "table table-layout-fixed"}
  165. exclude = ('resource_id', 'requirements', 'id_provider',
  166. 'id_metaservice', 'price_alg', 'service_status', 'ticket_status',
  167. 'is_global', 'is_visible')
  168. def render_check(self, value, record):
  169. if record.status == 'active':
  170. return format_html('<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-service-id="{}">', record.id)
  171. else:
  172. return format_html('<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-service-id="{}">', record.id)
  173. class UserInfoTable(tables.Table):
  174. id = tables.Column(verbose_name='ID', attrs={"td":{"width":"5%"}})
  175. class Meta:
  176. model = SharixUser
  177. attrs = {"class": "table table-layout-fixed"}
  178. exclude = ('password', 'phone_number',
  179. 'last_login','is_staff', 'is_superuser',
  180. 'date_joined')