tables.py 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. # description = tables.Column(verbose_name='Название тарифа', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  29. # description = tables.Column(verbose_name='Описание строки тарифов', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  30. # price_type = tables.Column(verbose_name='Тип тарифа', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  31. price_km = tables.Column(verbose_name='Стоимость км.', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  32. price_min = tables.Column(verbose_name='Стоимость мин.', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  33. price_amount = tables.Column(verbose_name='Стоимость услуги', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  34. status = tables.Column(verbose_name='Статус', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  35. check = tables.BooleanColumn(verbose_name='', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  36. paginate_by = 10
  37. class Meta:
  38. model = Service
  39. attrs = {"class": "table table-layout-fixed"}
  40. exclude = ('resource_id', 'requirements', 'id_provider',
  41. 'id_metaservice', 'price_alg', 'service_status', 'ticket_status',
  42. 'is_global', 'is_visible')
  43. def render_check(self, value, record):
  44. if record.status == 'active':
  45. return format_html('<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-service-id="{}">', record.id)
  46. else:
  47. return format_html('<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-service-id="{}">', record.id)