tables.py 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import django_tables2 as tables
  2. from .models import *
  3. from django.utils.html import format_html
  4. from metaservicesynced.models import *
  5. class TransactionsWalletTable(tables.Table):
  6. # id = tables.Column(order_by=True)
  7. id = tables.Column(verbose_name='#', orderable=False, attrs={"td":{"width":"5%"}})
  8. wallet = tables.Column(verbose_name='Владелец', orderable=False, attrs={"td":{"width":"15%"}})
  9. name_operation = tables.Column(verbose_name='Услуга', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  10. price = tables.Column(verbose_name='Баллы', attrs={"class":"row", "td":{"width":"10%"}})
  11. date_operation = tables.Column(verbose_name='Дата оформления', attrs={"td":{"width":"30%"}})
  12. is_carried_out = tables.BooleanColumn(verbose_name='Статус', orderable=False, yesno="Успешно,Не успешно", attrs={"td":{"width":"20%"}})
  13. class Meta:
  14. #model = TransactionsWallets
  15. attrs = {"class": "table table-striped"}
  16. exclude = ("balance_before",
  17. "amount",
  18. "metaservice_id",
  19. "transaction_type",
  20. "doc_num",
  21. "service_id")
  22. def render_name_operation(self, value, record):
  23. return format_html("<a href='{}'>{}</a>", record.get_absolute_url(), value)
  24. class ProviderTable(tables.Table):
  25. id = tables.Column(verbose_name='ID', attrs={"td":{"width":"5%"}})
  26. 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%"}})
  27. status = tables.Column(verbose_name='Статус', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  28. check = tables.BooleanColumn(verbose_name='', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  29. paginate_by = 10
  30. class Meta:
  31. model = Provider
  32. attrs = {"class": "table table-layout-fixed"}
  33. exclude = ('type','company_id','id_metaservice', 'requirements',
  34. 'ticket_status', 'location_type', 'default_location',
  35. 'is_global', 'is_visible')
  36. def render_check(self, value, record):
  37. if record.status == 'active':
  38. return format_html('<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-provider-id="{}">', record.id)
  39. else:
  40. return format_html('<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-provider-id="{}">', record.id)
  41. class ServiceTariffTable(tables.Table):
  42. id = tables.Column(verbose_name='ID', attrs={"td":{"width":"5%"}})
  43. servicetype_id = tables.LinkColumn('service_tariff/edit/', verbose_name='Название тарифа', text = lambda record: record.servicetype_id.caption,
  44. args=[tables.A('pk')], attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  45. ticket_status = tables.Column(verbose_name='Название схемы услуги', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  46. check = tables.BooleanColumn(verbose_name='Активность', orderable=False, attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  47. class Meta:
  48. model = Service
  49. attrs = {"class": "table table-layout-fixed"}
  50. exclude = ('resource_id','id_provider','price_alg',
  51. 'price_min','price_amount','id_metaservice',
  52. 'requirements', 'service_status', 'price_km',
  53. 'is_global', 'is_visible','status')
  54. def render_check(self, value, record):
  55. if record.status == 'active':
  56. return format_html('<input class="form-check-input status-toggle" disabled checked type="checkbox"')
  57. else:
  58. return format_html('<input class="form-check-input status-toggle" disabled type="checkbox"')