tables.py 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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 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. delete = 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 TasksTable(tables.Table):
  119. id = tables.Column(verbose_name=_('ID'), attrs={"td":{"width":"5%"}})
  120. task_description = tables.Column(verbose_name=_('Задача'), attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  121. dead_line = tables.Column(verbose_name=_('Дата'), attrs={"td":{"width":"10%"}})
  122. 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%"}})
  123. 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%"}})
  124. status = tables.Column(verbose_name=_('Status'), attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  125. check = tables.BooleanColumn(verbose_name='', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  126. edit = tables.LinkColumn('tech_support/edit/', verbose_name='', orderable=False, text = "E",
  127. args=[tables.A('pk')], attrs={'th':{'scope':'col'}, "td":{"class":"edit_col"}})
  128. delete = tables.LinkColumn('tech_support/delete/', verbose_name='', orderable=False, text = "D",
  129. args=[tables.A('pk')], attrs={'th':{'scope':'col'}, "td":{"class":"delete_col"}})
  130. class Meta:
  131. model = Tasks
  132. attrs = {"class": "table table-layout-fixed text-start"}
  133. exclude = ('ticket_status', 'id_metaservice',
  134. 'is_global', 'is_visible')
  135. def render_check(self, value, record):
  136. if record.status == 'active':
  137. return format_html('<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-tasks-id="{}">', record.id)
  138. else:
  139. return format_html('<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-tasks-id="{}">', record.id)
  140. class CommentsTable(tables.Table):
  141. id = tables.Column( attrs={"td":{"width":"50px"}})
  142. 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%"}})
  143. check = tables.BooleanColumn(verbose_name='', attrs={'th':{'scope':'col'}, "td":{"width":"5%"}})
  144. delete = tables.LinkColumn('comments/delete/', verbose_name='', orderable=False, text = "D",
  145. args=[tables.A('pk')], attrs={'th':{'scope':'col'}, "td":{"class":"delete_col"}})
  146. status = tables.Column(verbose_name=_('Status'), attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  147. class Meta:
  148. model = Comments
  149. attrs = {"class": "table table-layout-fixed text-start"}
  150. exclude = ('ticket_status', 'id_metaservice',
  151. 'is_global', 'is_visible')
  152. def render_check(self, value, record):
  153. if record.status == 'active':
  154. return format_html('<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-comments-id="{}">', record.id)
  155. else:
  156. return format_html('<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-comments-id="{}">', record.id)
  157. class TechSupTable(tables.Table):
  158. id = tables.Column( attrs={"td":{"width":"50px"}})
  159. 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%"}})
  160. description = tables.LinkColumn('tech_support/edit/', orderable=False, verbose_name='Описание', text = lambda record: record.description,
  161. args=[tables.A('pk')], attrs= {"a": {"style": "pointer-events: none;"}, 'th':{'scope':'col'}, "td":{"class":"description_col"}})
  162. edit = tables.LinkColumn('tech_support/edit/', verbose_name='', orderable=False, text = "E",
  163. args=[tables.A('pk')], attrs={'th':{'scope':'col'}, "td":{"class":"edit_col"}})
  164. delete = tables.LinkColumn('tech_support/delete/', verbose_name='', orderable=False, text = "D",
  165. args=[tables.A('pk')], attrs={'th':{'scope':'col'}, "td":{"class":"delete_col"}})
  166. status = tables.Column(verbose_name=_('Status'), attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  167. class Meta:
  168. model = Comments
  169. attrs = {"class": "table table-layout-fixed text-start"}
  170. exclude = ('ticket_status', 'id_metaservice',
  171. 'is_global', 'is_visible')
  172. class ServiceTable(tables.Table):
  173. id = tables.Column(attrs={"td":{"width":"5%"}})
  174. servicetype_id = tables.Column(verbose_name=_('Description of the service'), accessor = 'servicetype_id.caption',
  175. attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  176. id_provider = tables.Column(verbose_name=_('Организатор'))
  177. name_service = tables.Column(verbose_name=_('Экскурсия'))
  178. rating = tables.Column(verbose_name=_('Рейтинг'))
  179. price = tables.Column(verbose_name=_('Цена'))
  180. class Meta:
  181. model = Service
  182. attrs = {"class": "table table-layout-fixed"}
  183. exclude = ('resource_id','servicetype_id', 'requirements',
  184. 'id_metaservice', 'price_alg','price_km', 'price_min', 'price_amount', 'service_status', 'ticket_status',
  185. 'is_global', 'is_visible', 'place_start', 'place_end', 'movement_way', 'discription', 'status')
  186. def render_check(self, value, record):
  187. if record.status == 'active':
  188. return format_html('<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-service-id="{}">', record.id)
  189. else:
  190. return format_html('<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-service-id="{}">', record.id)
  191. class UserInfoTable(tables.Table):
  192. id = tables.Column(verbose_name=_('ID'), attrs={"td":{"width":"5%"}})
  193. delete = tables.LinkColumn('user_information/delete/', verbose_name='', orderable=False, text = "D",
  194. args=[tables.A('pk')], attrs={'th':{'scope':'col'}, "td":{"class":"delete_col"}})
  195. class Meta:
  196. model = get_user_model()
  197. attrs = {"class": "table table-layout-fixed"}
  198. exclude = ('password', 'phone_number', "avatar",
  199. 'last_login','is_staff', 'is_superuser',
  200. 'date_joined')