tables.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. import django_tables2 as tables
  2. from django.contrib.auth import get_user_model
  3. from dbsynce.models import *
  4. from django.utils.html import format_html
  5. from dbsynce.models import *
  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, yesno=_("Successful, not successful"), attrs={"td":{"width":"20%"}})
  15. class Meta:
  16. #model = TransactionsWallets
  17. attrs = {"class": "table table-striped"}
  18. exclude = ("balance_before",
  19. "amount",
  20. "metaservice_id",
  21. "transaction_type",
  22. "doc_num",
  23. "service_id")
  24. def render_name_operation(self, value, record):
  25. return format_html("<a href='{}'>{}</a>", record.get_absolute_url(), value)
  26. class PartnersTable(tables.Table):
  27. id = tables.Column(verbose_name=_('ID'), attrs={"td":{"width":"5%"}})
  28. legal_name = tables.Column(verbose_name=_('Legal entity'), 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=_('Responsible'), attrs={"td":{"width":"15%"}})
  30. status = tables.Column(verbose_name=_('Status'), 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 ResourceTable(tables.Table):
  46. id = tables.Column(verbose_name=_('ID'), attrs={"td":{"width":"5%"}})
  47. #В user_id ссылка LinkColumn на страницу Аси "Информация о партнере" страница partner_information_form
  48. user_id = tables.Column(accessor='user_id.full_name', order_by=('user_id.first_name', 'user_id.last_name'), verbose_name=_('Responsible'), attrs={"td":{"width":"15%"}})
  49. status = tables.Column(verbose_name=_('Status'), attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  50. check = tables.BooleanColumn(verbose_name='', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  51. # paginate_by = 10
  52. class Meta:
  53. model = Resource
  54. attrs = {"class": "table table-layout-fixed"}
  55. exclude = (
  56. 'id_metaservice',
  57. 'resoure_type',
  58. 'requirements',
  59. 'is_global',
  60. 'is_visible',
  61. 'ticket_status'
  62. )
  63. def render_check(self, value, record):
  64. if record.status == 'active':
  65. return format_html('<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-resource-id="{}">', record.id)
  66. else:
  67. return format_html('<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-resource-id="{}">', record.id)
  68. class ProviderTable(tables.Table):
  69. id = tables.Column(verbose_name=_('ID'), attrs={"td":{"width":"5%"}})
  70. user_id = tables.Column(accessor='user_id.full_name', order_by=('user_id.first_name', 'user_id.last_name'), verbose_name=_('Full Name'), 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 = Provider
  76. attrs = {"class": "table table-layout-fixed"}
  77. exclude = ('type','company_id','id_metaservice', 'requirements',
  78. 'ticket_status', 'location_type', 'default_location',
  79. 'is_global', 'is_visible')
  80. def render_check(self, value, record):
  81. if record.status == 'active':
  82. return format_html('<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-provider-id="{}">', record.id)
  83. else:
  84. return format_html('<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-provider-id="{}">', record.id)
  85. class ServiceTariffTable(tables.Table):
  86. id = tables.Column(verbose_name=_('ID'), attrs={"td":{"width":"5%"}})
  87. servicetype_id = tables.LinkColumn('service_tariff/edit/', verbose_name=_('Name of the tariff'), text = lambda record: record.servicetype_id.caption,
  88. args=[tables.A('pk')], attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  89. ticket_status = tables.Column(verbose_name=_('Name of the service scheme'), attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  90. check = tables.BooleanColumn(verbose_name=_('Activity'), orderable=False, attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  91. class Meta:
  92. model = Service
  93. attrs = {"class": "table table-layout-fixed"}
  94. exclude = (
  95. 'resource_id',
  96. 'price_alg',
  97. 'price_min',
  98. 'price_amount',
  99. 'id_metaservice',
  100. 'requirements',
  101. 'service_status',
  102. 'price_km',
  103. 'is_global',
  104. 'is_visible',
  105. 'status'
  106. )
  107. def render_check(self, value, record):
  108. if record.status == 'active':
  109. return format_html('<input class="form-check-input status-toggle" disabled checked type="checkbox"')
  110. else:
  111. return format_html('<input class="form-check-input status-toggle" disabled type="checkbox"')
  112. class ServiceTypeTable(tables.Table):
  113. id = tables.Column( attrs={"td":{"width":"50px"}})
  114. codename = tables.LinkColumn('service_type/edit/', verbose_name='Услуга', orderable=False, text = lambda record: record.codename,
  115. args=[tables.A('pk')], attrs= {"a": {"style": "pointer-events: none;"}, 'th':{'scope':'col'}, "td":{"class":"name_col"}})
  116. description = tables.LinkColumn('service_type/edit/', orderable=False, verbose_name='Описание', text = lambda record: record.description,
  117. args=[tables.A('pk')], attrs= {"a": {"style": "pointer-events: none;"}, 'th':{'scope':'col'}, "td":{"class":"description_col"}})
  118. edit = tables.LinkColumn('service_type/edit/', verbose_name='', orderable=False, text = "E",
  119. args=[tables.A('pk')], attrs={'th':{'scope':'col'}, "td":{"class":"edit_col"}})
  120. deletee = tables.LinkColumn('service_type/delete/', verbose_name='', orderable=False, text = "D",
  121. args=[tables.A('pk')], attrs={'th':{'scope':'col'}, "td":{"class":"delete_col"}})
  122. class Meta:
  123. model = ServiceType
  124. attrs = {"class": "table table-layout-fixed text-start"}
  125. exclude = ('requirements',
  126. 'price_type','status','ticket_status',
  127. 'id_metaservice', 'link_agreement',
  128. 'is_global', 'is_visible', 'caption')
  129. # def render_delete(self, value, record):
  130. # return format_html('<a href="/service_type/delete" class="btn btn-outline-danger">_(Delete)</a>')
  131. # def render_name_operation(self, value, record):
  132. # return format_html("<a href='{}'>{}</a>", record.get_absolute_url(), value)
  133. class ServiceTable(tables.Table):
  134. id = tables.Column(verbose_name=_('ID'), attrs={"td":{"width":"5%"}})
  135. servicetype_id = tables.Column(verbose_name=_('Description of the service'), accessor = 'servicetype_id.caption',
  136. attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  137. # description = tables.Column(verbose_name='Название тарифа', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  138. # description = tables.Column(verbose_name='Описание строки тарифов', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  139. # price_type = tables.Column(verbose_name='Тип тарифа', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  140. price_km = tables.Column(verbose_name=_('Cost km.'), attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  141. price_min = tables.Column(verbose_name=_('Cost min.'), attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  142. price_amount = tables.Column(verbose_name=_('Cost of service'), attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  143. class Meta:
  144. model = Service
  145. attrs = {"class": "table table-layout-fixed"}
  146. exclude = (
  147. 'resource_id',
  148. 'requirements',
  149. 'id_metaservice',
  150. 'price_alg',
  151. 'service_status',
  152. 'ticket_status',
  153. 'is_global',
  154. 'is_visible'
  155. )
  156. def render_check(self, value, record):
  157. if record.status == 'active':
  158. return format_html('<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-service-id="{}">', record.id)
  159. else:
  160. return format_html('<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-service-id="{}">', record.id)
  161. class UserInfoTable(tables.Table):
  162. id = tables.Column(verbose_name=_('ID'), attrs={"td":{"width":"5%"}})
  163. class Meta:
  164. model = get_user_model()
  165. attrs = {"class": "table table-layout-fixed"}
  166. exclude = ('password', 'phone_number',
  167. 'last_login','is_staff', 'is_superuser',
  168. 'date_joined')