tables.py 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. import django_tables2 as tables
  2. from dbsynce.models import *
  3. from dbsynce.models import *
  4. from django.contrib.auth import get_user_model
  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(
  10. verbose_name='#',
  11. orderable=False,
  12. attrs={
  13. "td": {"width": "5%"}
  14. }
  15. )
  16. wallet = tables.Column(
  17. verbose_name=_('Owner'),
  18. orderable=False,
  19. attrs={
  20. "td": {"width": "15%"}
  21. }
  22. )
  23. name_operation = tables.Column(
  24. verbose_name=_('Service'),
  25. attrs={
  26. 'th': {'scope': 'col'},
  27. "td": {"width": "20%"}
  28. }
  29. )
  30. price = tables.Column(
  31. verbose_name=_('Points'),
  32. attrs={
  33. "class": "row",
  34. "td": {"width": "10%"}
  35. }
  36. )
  37. date_operation = tables.Column(
  38. verbose_name=_('Registration date'),
  39. attrs={
  40. "td": {"width": "30%"}
  41. }
  42. )
  43. is_carried_out = tables.BooleanColumn(
  44. verbose_name=_('Status'),
  45. orderable=False,
  46. yesno=_("Successful, not successful"),
  47. attrs={
  48. "td": {"width": "20%"}
  49. }
  50. )
  51. class Meta:
  52. # model = TransactionsWallets
  53. attrs = {
  54. "class": "table table-striped"
  55. }
  56. exclude = (
  57. "balance_before",
  58. "amount",
  59. "metaservice_id",
  60. "transaction_type",
  61. "doc_num",
  62. "service_id"
  63. )
  64. def render_name_operation(self, value, record):
  65. return format_html(
  66. "<a href='{}'>{}</a>",
  67. record.get_absolute_url(),
  68. value
  69. )
  70. class PartnersTable(tables.Table):
  71. id = tables.Column(
  72. verbose_name=_('ID'),
  73. attrs={
  74. "td": {"width": "5%"}
  75. }
  76. )
  77. legal_name = tables.Column(
  78. verbose_name=_('Legal entity'),
  79. attrs={
  80. 'th': {'scope': 'col'},
  81. "td": {"width": "20%"}
  82. }
  83. )
  84. repr = tables.Column(
  85. accessor='repr.full_name',
  86. order_by=('repr.first_name', 'repr.last_name'),
  87. verbose_name=_('Responsible'),
  88. attrs={
  89. "td": {"width": "15%"}
  90. }
  91. )
  92. status = tables.Column(
  93. verbose_name=_('Status'),
  94. attrs={
  95. 'th': {'scope': 'col'},
  96. "td": {"width": "20%"}
  97. }
  98. )
  99. check = tables.BooleanColumn(
  100. verbose_name='',
  101. attrs={
  102. 'th': {'scope': 'col'},
  103. "td": {"width": "20%"}
  104. }
  105. )
  106. # paginate_by = 10
  107. class Meta:
  108. model = Company
  109. attrs = {
  110. "class": "table table-layout-fixed"
  111. }
  112. exclude = (
  113. 'inn',
  114. 'kpp',
  115. 'ogrn',
  116. 'bank_name',
  117. 'bik',
  118. 'ks',
  119. 'rs',
  120. 'address',
  121. 'requirements',
  122. 'id_metaservice',
  123. 'is_global',
  124. 'is_visible',
  125. 'ticket_status'
  126. )
  127. def render_check(self, value, record):
  128. if record.status == 'active':
  129. return format_html(
  130. '<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-partners-id="{}">',
  131. record.id
  132. )
  133. else:
  134. return format_html(
  135. '<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-partners-id="{}">',
  136. record.id
  137. )
  138. class ResourceTable(tables.Table):
  139. id = tables.Column(
  140. verbose_name=_('ID'),
  141. attrs={
  142. "td": {"width": "5%"}
  143. }
  144. )
  145. # В user ссылка LinkColumn на страницу Аси "Информация о партнере" страница partner_information_form
  146. user = tables.Column(
  147. accessor='user.full_name',
  148. order_by=('user.first_name', 'user.last_name'),
  149. verbose_name=_('Responsible'),
  150. attrs={
  151. "td": {"width": "15%"}
  152. }
  153. )
  154. status = tables.Column(
  155. verbose_name=_('Status'),
  156. attrs={
  157. 'th': {'scope': 'col'},
  158. "td": {"width": "20%"}
  159. }
  160. )
  161. check = tables.BooleanColumn(
  162. verbose_name='',
  163. attrs={
  164. 'th': {'scope': 'col'},
  165. "td": {"width": "20%"}
  166. }
  167. )
  168. # paginate_by = 10
  169. class Meta:
  170. model = Resource
  171. attrs = {
  172. "class": "table table-layout-fixed"
  173. }
  174. exclude = (
  175. 'id_metaservice',
  176. 'resoure_type',
  177. 'requirements',
  178. 'is_global',
  179. 'is_visible',
  180. 'ticket_status'
  181. )
  182. def render_check(self, value, record):
  183. if record.status == 'active':
  184. return format_html(
  185. '<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-resource-id="{}">',
  186. record.id
  187. )
  188. else:
  189. return format_html(
  190. '<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-resource-id="{}">',
  191. record.id
  192. )
  193. class ProviderTable(tables.Table):
  194. id = tables.Column(
  195. verbose_name=_('ID'),
  196. attrs={
  197. "td": {"width": "5%"}
  198. }
  199. )
  200. user = tables.Column(
  201. accessor='user.full_name',
  202. order_by=('user.first_name', 'user.last_name'),
  203. verbose_name=_('Full Name'),
  204. attrs={
  205. "td": {"width": "15%"}
  206. }
  207. )
  208. status = tables.Column(
  209. verbose_name=_('Status'),
  210. attrs={
  211. 'th': {'scope': 'col'},
  212. "td": {"width": "20%"}
  213. }
  214. )
  215. check = tables.BooleanColumn(
  216. verbose_name='',
  217. attrs={
  218. 'th': {'scope': 'col'},
  219. "td": {"width": "20%"}
  220. }
  221. )
  222. paginate_by = 10
  223. class Meta:
  224. model = Provider
  225. attrs = {
  226. "class": "table table-layout-fixed"
  227. }
  228. exclude = (
  229. 'type',
  230. 'company',
  231. 'id_metaservice',
  232. 'requirements',
  233. 'ticket_status',
  234. 'location_type',
  235. 'default_location',
  236. 'is_global',
  237. 'is_visible'
  238. )
  239. def render_check(self, value, record):
  240. if record.status == 'active':
  241. return format_html(
  242. '<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-provider-id="{}">',
  243. record.id
  244. )
  245. else:
  246. return format_html(
  247. '<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-provider-id="{}">',
  248. record.id
  249. )
  250. class ServiceTariffTable(tables.Table):
  251. id = tables.Column(
  252. verbose_name=_('ID'),
  253. attrs={
  254. "td": {"width": "5%"}
  255. }
  256. )
  257. servicetype = tables.LinkColumn(
  258. 'service_tariff/edit/',
  259. verbose_name=_('Name of the tariff'),
  260. text=lambda record: record.servicetype.caption,
  261. args=[tables.A('pk')],
  262. attrs={
  263. 'th': {'scope': 'col'},
  264. "td": {"width": "20%"}
  265. }
  266. )
  267. ticket_status = tables.Column(
  268. verbose_name=_('Name of the service scheme'),
  269. attrs={
  270. 'th': {'scope': 'col'},
  271. "td": {"width": "20%"}
  272. }
  273. )
  274. check = tables.BooleanColumn(
  275. verbose_name=_('Activity'),
  276. orderable=False,
  277. attrs={
  278. 'th': {'scope': 'col'},
  279. "td": {"width": "20%"}
  280. }
  281. )
  282. class Meta:
  283. model = Service
  284. attrs = {
  285. "class": "table table-layout-fixed"
  286. }
  287. exclude = (
  288. 'resource',
  289. 'price_alg',
  290. 'price_min',
  291. 'price_amount',
  292. 'id_metaservice',
  293. 'requirements',
  294. 'service_status',
  295. 'price_km',
  296. 'is_global',
  297. 'is_visible',
  298. 'status'
  299. )
  300. def render_check(self, value, record):
  301. if record.status == 'active':
  302. return format_html('<input class="form-check-input status-toggle" disabled checked type="checkbox"')
  303. else:
  304. return format_html('<input class="form-check-input status-toggle" disabled type="checkbox"')
  305. class ServiceTypeTable(tables.Table):
  306. id = tables.Column(attrs={"td": {"width": "50px"}})
  307. codename = tables.LinkColumn(
  308. 'service_type/edit/',
  309. verbose_name='Услуга',
  310. orderable=False,
  311. text=lambda record: record.codename,
  312. args=[tables.A('pk')],
  313. attrs={
  314. "a": {"style": "pointer-events: none;"},
  315. 'th': {'scope': 'col'},
  316. "td": {"class": "name_col"}
  317. }
  318. )
  319. description = tables.LinkColumn(
  320. 'service_type/edit/',
  321. orderable=False, verbose_name='Описание',
  322. text=lambda record: record.description,
  323. args=[tables.A('pk')],
  324. attrs={
  325. "a": {"style": "pointer-events: none;"},
  326. 'th': {'scope': 'col'},
  327. "td": {"class": "description_col"}
  328. }
  329. )
  330. edit = tables.LinkColumn(
  331. 'service_type/edit/',
  332. verbose_name='',
  333. orderable=False,
  334. text="E",
  335. args=[tables.A('pk')],
  336. attrs={
  337. 'th': {'scope': 'col'},
  338. "td": {"class": "edit_col"}
  339. }
  340. )
  341. deletee = tables.LinkColumn(
  342. 'service_type/delete/',
  343. verbose_name='',
  344. orderable=False,
  345. text="D",
  346. args=[tables.A('pk')],
  347. attrs={
  348. 'th': {'scope': 'col'},
  349. "td": {"class": "delete_col"}
  350. }
  351. )
  352. class Meta:
  353. model = ServiceType
  354. attrs = {
  355. "class": "table table-layout-fixed text-start"
  356. }
  357. exclude = (
  358. 'requirements',
  359. 'price_type',
  360. 'status',
  361. 'ticket_status',
  362. 'id_metaservice',
  363. 'link_agreement',
  364. 'is_global',
  365. 'is_visible',
  366. 'caption'
  367. )
  368. # def render_delete(self, value, record):
  369. # return format_html('<a href="/service_type/delete" class="btn btn-outline-danger">_(Delete)</a>')
  370. # def render_name_operation(self, value, record):
  371. # return format_html("<a href='{}'>{}</a>", record.get_absolute_url(), value)
  372. class ServiceTable(tables.Table):
  373. id = tables.Column(
  374. verbose_name=_('ID'),
  375. attrs={
  376. "td": {"width": "5%"}
  377. }
  378. )
  379. servicetype = tables.Column(
  380. verbose_name=_('Description of the service'),
  381. accessor='servicetype.caption',
  382. attrs={
  383. 'th': {'scope': 'col'},
  384. "td": {"width": "20%"}}
  385. )
  386. # description = tables.Column(verbose_name='Название тарифа', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  387. # description = tables.Column(verbose_name='Описание строки тарифов', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  388. # price_type = tables.Column(verbose_name='Тип тарифа', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  389. price_km = tables.Column(
  390. verbose_name=_('Cost km.'),
  391. attrs={
  392. 'th': {'scope': 'col'},
  393. "td": {"width": "20%"}
  394. }
  395. )
  396. price_min = tables.Column(
  397. verbose_name=_('Cost min.'),
  398. attrs={
  399. 'th': {'scope': 'col'},
  400. "td": {"width": "20%"}}
  401. )
  402. price_amount = tables.Column(
  403. verbose_name=_('Cost of service'),
  404. attrs={
  405. 'th': {'scope': 'col'},
  406. "td": {"width": "20%"}
  407. }
  408. )
  409. class Meta:
  410. model = Service
  411. attrs = {
  412. "class": "table table-layout-fixed"
  413. }
  414. exclude = (
  415. 'resource',
  416. 'requirements',
  417. 'id_metaservice',
  418. 'price_alg',
  419. 'service_status',
  420. 'ticket_status',
  421. 'is_global',
  422. 'is_visible'
  423. )
  424. def render_check(self, value, record):
  425. if record.status == 'active':
  426. return format_html(
  427. '<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-service-id="{}">',
  428. record.id
  429. )
  430. else:
  431. return format_html(
  432. '<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-service-id="{}">',
  433. record.id
  434. )
  435. class UserInfoTable(tables.Table):
  436. id = tables.Column(
  437. verbose_name=_('ID'),
  438. attrs={
  439. "td": {"width": "5%"}
  440. }
  441. )
  442. class Meta:
  443. model = get_user_model()
  444. attrs = {
  445. "class": "table table-layout-fixed"
  446. }
  447. exclude = (
  448. 'password',
  449. 'phone_number',
  450. 'last_login',
  451. 'is_staff',
  452. 'is_superuser',
  453. 'date_joined'
  454. )