tables.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 = ('type_id','requirements','ticket_status', 'id_metaservice',
  56. 'is_global', 'is_visible')
  57. def render_check(self, value, record):
  58. if record.status == 'active':
  59. return format_html('<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-resource-id="{}">', record.id)
  60. else:
  61. return format_html('<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-resource-id="{}">', record.id)
  62. class ProviderTable(tables.Table):
  63. id = tables.Column(verbose_name=_('ID'), attrs={"td":{"width":"5%"}})
  64. 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%"}})
  65. status = tables.Column(verbose_name=_('Status'), attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  66. check = tables.BooleanColumn(verbose_name='', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  67. paginate_by = 10
  68. class Meta:
  69. model = Provider
  70. attrs = {"class": "table table-layout-fixed"}
  71. exclude = ('type','company_id','id_metaservice', 'requirements',
  72. 'ticket_status', 'location_type', 'default_location',
  73. 'is_global', 'is_visible')
  74. def render_check(self, value, record):
  75. if record.status == 'active':
  76. return format_html('<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-provider-id="{}">', record.id)
  77. else:
  78. return format_html('<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-provider-id="{}">', record.id)
  79. class ServiceTariffTable(tables.Table):
  80. id = tables.Column(verbose_name=_('ID'), attrs={"td":{"width":"5%"}})
  81. servicetype_id = tables.LinkColumn('service_tariff/edit/', verbose_name=_('Name of the tariff'), text = lambda record: record.servicetype_id.caption,
  82. args=[tables.A('pk')], attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  83. ticket_status = tables.Column(verbose_name=_('Name of the service scheme'), attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  84. check = tables.BooleanColumn(verbose_name=_('Activity'), orderable=False, attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  85. class Meta:
  86. model = Service
  87. attrs = {"class": "table table-layout-fixed"}
  88. exclude = ('resource_id','id_provider','price_alg',
  89. 'price_min','price_amount','id_metaservice',
  90. 'requirements', 'service_status', 'price_km',
  91. 'is_global', 'is_visible','status')
  92. def render_check(self, value, record):
  93. if record.status == 'active':
  94. return format_html('<input class="form-check-input status-toggle" disabled checked type="checkbox"')
  95. else:
  96. return format_html('<input class="form-check-input status-toggle" disabled type="checkbox"')
  97. class ServiceTypeTable(tables.Table):
  98. id = tables.Column( attrs={"td":{"width":"50px"}})
  99. codename = tables.LinkColumn('service_type/edit/', verbose_name='Услуга', orderable=False, text = lambda record: record.codename,
  100. args=[tables.A('pk')], attrs= {"a": {"style": "pointer-events: none;"}, 'th':{'scope':'col'}, "td":{"class":"name_col"}})
  101. description = tables.LinkColumn('service_type/edit/', orderable=False, verbose_name='Описание', text = lambda record: record.description,
  102. args=[tables.A('pk')], attrs= {"a": {"style": "pointer-events: none;"}, 'th':{'scope':'col'}, "td":{"class":"description_col"}})
  103. edit = tables.LinkColumn('service_type/edit/', verbose_name='', orderable=False, text = "E",
  104. args=[tables.A('pk')], attrs={'th':{'scope':'col'}, "td":{"class":"edit_col"}})
  105. deletee = tables.LinkColumn('service_type/delete/', verbose_name='', orderable=False, text = "D",
  106. args=[tables.A('pk')], attrs={'th':{'scope':'col'}, "td":{"class":"delete_col"}})
  107. class Meta:
  108. model = ServiceType
  109. attrs = {"class": "table table-layout-fixed text-start"}
  110. exclude = ('requirements',
  111. 'price_type','status','ticket_status',
  112. 'id_metaservice', 'link_agreement',
  113. 'is_global', 'is_visible', 'caption')
  114. # def render_delete(self, value, record):
  115. # return format_html('<a href="/service_type/delete" class="btn btn-outline-danger">_(Delete)</a>')
  116. # def render_name_operation(self, value, record):
  117. # return format_html("<a href='{}'>{}</a>", record.get_absolute_url(), value)
  118. class ServiceTable(tables.Table):
  119. id = tables.Column(verbose_name=_('ID'), attrs={"td":{"width":"5%"}})
  120. servicetype_id = tables.Column(verbose_name=_('Description of the service'), accessor = 'servicetype_id.caption',
  121. attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  122. # description = tables.Column(verbose_name='Название тарифа', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  123. # description = tables.Column(verbose_name='Описание строки тарифов', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  124. # price_type = tables.Column(verbose_name='Тип тарифа', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  125. price_km = tables.Column(verbose_name=_('Cost km.'), attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  126. price_min = tables.Column(verbose_name=_('Cost min.'), attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  127. price_amount = tables.Column(verbose_name=_('Cost of service'), attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  128. class Meta:
  129. model = Service
  130. attrs = {"class": "table table-layout-fixed"}
  131. exclude = ('resource_id', 'requirements', 'id_provider',
  132. 'id_metaservice', 'price_alg', 'service_status', 'ticket_status',
  133. 'is_global', 'is_visible')
  134. def render_check(self, value, record):
  135. if record.status == 'active':
  136. return format_html('<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-service-id="{}">', record.id)
  137. else:
  138. return format_html('<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-service-id="{}">', record.id)
  139. class UserInfoTable(tables.Table):
  140. id = tables.Column(verbose_name=_('ID'), attrs={"td":{"width":"5%"}})
  141. class Meta:
  142. model = get_user_model()
  143. attrs = {"class": "table table-layout-fixed"}
  144. exclude = ('password', 'phone_number',
  145. 'last_login','is_staff', 'is_superuser',
  146. 'date_joined')