1
0

tables.py 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. import django_tables2 as tables
  2. from django.contrib.auth import get_user_model
  3. from dbsynce.models import *
  4. from webservice_running.models import *
  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, 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 TaskTable(tables.Table):
  46. id = tables.Column(verbose_name=_('ID'), attrs={"td":{"width":"5%"}})
  47. legal_name = tables.Column(verbose_name=_('Legal entity'), attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  48. 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%"}})
  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 = Company
  54. attrs = {"class": "table table-layout-fixed"}
  55. exclude = ('inn','kpp','ogrn', 'bank_name',
  56. 'bik', 'ks', 'rs',
  57. 'address', 'requirements',
  58. 'id_metaservice', 'is_global', 'is_visible', 'ticket_status')
  59. def render_check(self, value, record):
  60. if record.status == 'active':
  61. return format_html('<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-partners-id="{}">', record.id)
  62. else:
  63. return format_html('<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-partners-id="{}">', record.id)
  64. class ResourceTable(tables.Table):
  65. id = tables.Column(verbose_name=_('ID'), attrs={"td":{"width":"5%"}})
  66. #В user_id ссылка LinkColumn на страницу Аси "Информация о партнере" страница partner_information_form
  67. 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%"}})
  68. status = tables.Column(verbose_name=_('Status'), 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 = Resource
  73. attrs = {"class": "table table-layout-fixed"}
  74. exclude = ('type_id','requirements','ticket_status', 'id_metaservice',
  75. 'is_global', 'is_visible')
  76. def render_check(self, value, record):
  77. if record.status == 'active':
  78. return format_html('<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-resource-id="{}">', record.id)
  79. else:
  80. return format_html('<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-resource-id="{}">', record.id)
  81. class ProviderTable(tables.Table):
  82. id = tables.Column(verbose_name=_('ID'), attrs={"td":{"width":"5%"}})
  83. 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%"}})
  84. status = tables.Column(verbose_name=_('Status'), attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  85. check = tables.BooleanColumn(verbose_name='', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  86. paginate_by = 10
  87. class Meta:
  88. model = Provider
  89. attrs = {"class": "table table-layout-fixed"}
  90. exclude = ('type','company_id','id_metaservice', 'requirements',
  91. 'ticket_status', 'location_type', 'default_location',
  92. 'is_global', 'is_visible')
  93. def render_check(self, value, record):
  94. if record.status == 'active':
  95. return format_html('<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-provider-id="{}">', record.id)
  96. else:
  97. return format_html('<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-provider-id="{}">', record.id)
  98. class ServiceTariffTable(tables.Table):
  99. id = tables.Column(verbose_name=_('ID'), attrs={"td":{"width":"5%"}})
  100. servicetype_id = tables.LinkColumn('service_tariff/edit/', verbose_name=_('Name of the tariff'), text = lambda record: record.servicetype_id.caption,
  101. args=[tables.A('pk')], attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  102. ticket_status = tables.Column(verbose_name=_('Name of the service scheme'), attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  103. check = tables.BooleanColumn(verbose_name=_('Activity'), orderable=False, attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  104. class Meta:
  105. model = Service
  106. attrs = {"class": "table table-layout-fixed"}
  107. exclude = ('resource_id','id_provider','price_alg',
  108. 'price_min','price_amount','id_metaservice',
  109. 'requirements', 'service_status', 'price_km',
  110. 'is_global', 'is_visible','status')
  111. def render_check(self, value, record):
  112. if record.status == 'active':
  113. return format_html('<input class="form-check-input status-toggle" disabled checked type="checkbox"')
  114. else:
  115. return format_html('<input class="form-check-input status-toggle" disabled type="checkbox"')
  116. class ServiceTypeTable(tables.Table):
  117. id = tables.Column( attrs={"td":{"width":"50px"}})
  118. codename = tables.LinkColumn('service_type/edit/', verbose_name='Услуга', orderable=False, text = lambda record: record.codename,
  119. args=[tables.A('pk')], attrs= {"a": {"style": "pointer-events: none;"}, 'th':{'scope':'col'}, "td":{"class":"name_col"}})
  120. description = tables.LinkColumn('service_type/edit/', orderable=False, verbose_name='Описание', text = lambda record: record.description,
  121. args=[tables.A('pk')], attrs= {"a": {"style": "pointer-events: none;"}, 'th':{'scope':'col'}, "td":{"class":"description_col"}})
  122. edit = tables.LinkColumn('service_type/edit/', verbose_name='', orderable=False, text = "E",
  123. args=[tables.A('pk')], attrs={'th':{'scope':'col'}, "td":{"class":"edit_col"}})
  124. delete = tables.LinkColumn('service_type/delete/', verbose_name='', orderable=False, text = "D",
  125. args=[tables.A('pk')], attrs={'th':{'scope':'col'}, "td":{"class":"delete_col"}})
  126. class Meta:
  127. model = ServiceType
  128. attrs = {"class": "table table-layout-fixed text-start"}
  129. exclude = ('requirements',
  130. 'price_type','status','ticket_status',
  131. 'id_metaservice', 'link_agreement',
  132. 'is_global', 'is_visible', 'caption')
  133. # def render_delete(self, value, record):
  134. # return format_html('<a href="/service_type/delete" class="btn btn-outline-danger">_(Delete)</a>')
  135. # def render_name_operation(self, value, record):
  136. # return format_html("<a href='{}'>{}</a>", record.get_absolute_url(), value)
  137. class CommentsTable(tables.Table):
  138. id = tables.Column( attrs={"td":{"width":"50px"}})
  139. user_id = tables.Column(accessor='user_id.full_name', order_by=('user_id.first_name', 'user_id.last_name'), verbose_name=_('User'), attrs={"td":{"width":"15%"}})
  140. check = tables.BooleanColumn(verbose_name='', attrs={'th':{'scope':'col'}, "td":{"width":"5%"}})
  141. delete = tables.LinkColumn('comments/delete/', verbose_name='', orderable=False, text = "D",
  142. args=[tables.A('pk')], attrs={'th':{'scope':'col'}, "td":{"class":"delete_col"}})
  143. status = tables.Column(verbose_name=_('Status'), attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  144. class Meta:
  145. model = Comments
  146. attrs = {"class": "table table-layout-fixed text-start"}
  147. exclude = ('ticket_status', 'id_metaservice',
  148. 'is_global', 'is_visible')
  149. def render_check(self, value, record):
  150. if record.status == 'active':
  151. return format_html('<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-comments-id="{}">', record.id)
  152. else:
  153. return format_html('<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-comments-id="{}">', record.id)
  154. class TechSupTable(tables.Table):
  155. id = tables.Column( attrs={"td":{"width":"50px"}})
  156. user_id = tables.Column(accessor='user_id.full_name', order_by=('user_id.first_name', 'user_id.last_name'), verbose_name=_('User'), attrs={"td":{"width":"15%"}})
  157. description = tables.LinkColumn('tech_support/edit/', orderable=False, verbose_name='Описание', text = lambda record: record.description,
  158. args=[tables.A('pk')], attrs= {"a": {"style": "pointer-events: none;"}, 'th':{'scope':'col'}, "td":{"class":"description_col"}})
  159. edit = tables.LinkColumn('tech_support/edit/', verbose_name='', orderable=False, text = "E",
  160. args=[tables.A('pk')], attrs={'th':{'scope':'col'}, "td":{"class":"edit_col"}})
  161. delete = tables.LinkColumn('tech_support/delete/', verbose_name='', orderable=False, text = "D",
  162. args=[tables.A('pk')], attrs={'th':{'scope':'col'}, "td":{"class":"delete_col"}})
  163. status = tables.Column(verbose_name=_('Status'), attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  164. class Meta:
  165. model = Comments
  166. attrs = {"class": "table table-layout-fixed text-start"}
  167. exclude = ('ticket_status', 'id_metaservice',
  168. 'is_global', 'is_visible')
  169. class ServiceTable(tables.Table):
  170. id = tables.Column(attrs={"td":{"width":"5%"}})
  171. servicetype_id = tables.Column(verbose_name=_('Description of the service'), accessor = 'servicetype_id.caption',
  172. attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  173. id_provider = tables.Column(verbose_name=_('Организатор'))
  174. name_service = tables.Column(verbose_name=_('Экскурсия'))
  175. rating = tables.Column(verbose_name=_('Рейтинг'))
  176. price = tables.Column(verbose_name=_('Цена'))
  177. class Meta:
  178. model = Service
  179. attrs = {"class": "table table-layout-fixed"}
  180. exclude = ('resource_id','servicetype_id', 'requirements',
  181. 'id_metaservice', 'price_alg','price_km', 'price_min', 'price_amount', 'service_status', 'ticket_status',
  182. 'is_global', 'is_visible', 'place_start', 'place_end', 'movement_way', 'discription', 'status')
  183. def render_check(self, value, record):
  184. if record.status == 'active':
  185. return format_html('<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-service-id="{}">', record.id)
  186. else:
  187. return format_html('<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-service-id="{}">', record.id)
  188. class UserInfoTable(tables.Table):
  189. id = tables.Column(verbose_name=_('ID'), attrs={"td":{"width":"5%"}})
  190. delete = tables.LinkColumn('user_information/delete/', verbose_name='', orderable=False, text = "D",
  191. args=[tables.A('pk')], attrs={'th':{'scope':'col'}, "td":{"class":"delete_col"}})
  192. class Meta:
  193. model = get_user_model()
  194. attrs = {"class": "table table-layout-fixed"}
  195. exclude = ('password', 'phone_number', "avatar",
  196. 'last_login','is_staff', 'is_superuser',
  197. 'date_joined')