tables.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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 = ('resource_id','id_provider','price_alg',
  95. 'price_min','price_amount','id_metaservice',
  96. 'requirements', 'service_status', 'price_km',
  97. 'is_global', 'is_visible','status')
  98. def render_check(self, value, record):
  99. if record.status == 'active':
  100. return format_html('<input class="form-check-input status-toggle" disabled checked type="checkbox"')
  101. else:
  102. return format_html('<input class="form-check-input status-toggle" disabled type="checkbox"')
  103. class ServiceTypeTable(tables.Table):
  104. id = tables.Column( attrs={"td":{"width":"50px"}})
  105. codename = tables.LinkColumn('service_type/edit/', verbose_name='Услуга', orderable=False, text = lambda record: record.codename,
  106. args=[tables.A('pk')], attrs= {"a": {"style": "pointer-events: none;"}, 'th':{'scope':'col'}, "td":{"class":"name_col"}})
  107. description = tables.LinkColumn('service_type/edit/', orderable=False, verbose_name='Описание', text = lambda record: record.description,
  108. args=[tables.A('pk')], attrs= {"a": {"style": "pointer-events: none;"}, 'th':{'scope':'col'}, "td":{"class":"description_col"}})
  109. edit = tables.LinkColumn('service_type/edit/', verbose_name='', orderable=False, text = "E",
  110. args=[tables.A('pk')], attrs={'th':{'scope':'col'}, "td":{"class":"edit_col"}})
  111. deletee = tables.LinkColumn('service_type/delete/', verbose_name='', orderable=False, text = "D",
  112. args=[tables.A('pk')], attrs={'th':{'scope':'col'}, "td":{"class":"delete_col"}})
  113. class Meta:
  114. model = ServiceType
  115. attrs = {"class": "table table-layout-fixed text-start"}
  116. exclude = ('requirements',
  117. 'price_type','status','ticket_status',
  118. 'id_metaservice', 'link_agreement',
  119. 'is_global', 'is_visible', 'caption')
  120. # def render_delete(self, value, record):
  121. # return format_html('<a href="/service_type/delete" class="btn btn-outline-danger">_(Delete)</a>')
  122. # def render_name_operation(self, value, record):
  123. # return format_html("<a href='{}'>{}</a>", record.get_absolute_url(), value)
  124. class ServiceTable(tables.Table):
  125. id = tables.Column(verbose_name=_('ID'), attrs={"td":{"width":"5%"}})
  126. servicetype_id = tables.Column(verbose_name=_('Description of the service'), accessor = 'servicetype_id.caption',
  127. attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  128. # description = tables.Column(verbose_name='Название тарифа', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  129. # description = tables.Column(verbose_name='Описание строки тарифов', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  130. # price_type = tables.Column(verbose_name='Тип тарифа', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  131. price_km = tables.Column(verbose_name=_('Cost km.'), attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  132. price_min = tables.Column(verbose_name=_('Cost min.'), attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  133. price_amount = tables.Column(verbose_name=_('Cost of service'), attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  134. class Meta:
  135. model = Service
  136. attrs = {"class": "table table-layout-fixed"}
  137. exclude = ('resource_id', 'requirements', 'id_provider',
  138. 'id_metaservice', 'price_alg', 'service_status', 'ticket_status',
  139. 'is_global', 'is_visible')
  140. def render_check(self, value, record):
  141. if record.status == 'active':
  142. return format_html('<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-service-id="{}">', record.id)
  143. else:
  144. return format_html('<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-service-id="{}">', record.id)
  145. class UserInfoTable(tables.Table):
  146. id = tables.Column(verbose_name=_('ID'), attrs={"td":{"width":"5%"}})
  147. class Meta:
  148. model = get_user_model()
  149. attrs = {"class": "table table-layout-fixed"}
  150. exclude = ('password', 'phone_number',
  151. 'last_login','is_staff', 'is_superuser',
  152. 'date_joined')