tables.py 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import django_tables2 as tables
  2. from metaservicesynced.models import *
  3. from .models import *
  4. from django.utils.html import format_html
  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 ServiceTable(tables.Table):
  25. id = tables.Column(verbose_name='ID', attrs={"td":{"width":"5%"}})
  26. servicetype_id = tables.Column(verbose_name='Название тарифа', accessor = 'servicetype_id.caption',
  27. attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  28. # servicetype_id = tables.Column(verbose_name='Название тарифа', accessor = 'servicetype_id.description',
  29. # attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  30. price_km = tables.Column(verbose_name='Стоимость км.', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  31. price_min = tables.Column(verbose_name='Стоимость мин.', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  32. price_amount = tables.Column(verbose_name='Стоимость услуги', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  33. status = tables.Column(verbose_name='Статус', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  34. check = tables.BooleanColumn(verbose_name='', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  35. paginate_by = 10
  36. class Meta:
  37. model = Service
  38. attrs = {"class": "table table-layout-fixed"}
  39. exclude = ('resource_id', 'requirements', 'id_provider',
  40. 'id_metaservice', 'price_alg', 'service_status', 'ticket_status',
  41. 'is_global', 'is_visible')
  42. def render_check(self, value, record):
  43. if record.status == 'active':
  44. return format_html('<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-service-id="{}">', record.id)
  45. else:
  46. return format_html('<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-service-id="{}">', record.id)