tables.py 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  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 ResourcesTable(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.get_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. 'resource_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 ProvidersTable(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. 'id_metaservice',
  230. 'gap',
  231. 'requirements',
  232. 'status',
  233. 'service_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 ServiceTariffsTable(tables.Table):
  251. id = tables.Column(
  252. verbose_name=_('ID'),
  253. attrs={
  254. "td": {"width": "5%"}
  255. }
  256. )
  257. codename = tables.LinkColumn(
  258. 'sharix_admin:service_tariff/edit/',
  259. verbose_name=_('Кодовое название'),
  260. text=lambda record: record.caption,
  261. args=[tables.A('pk')],
  262. attrs={
  263. 'th': {'scope': 'col'},
  264. "td": {"width": "15%"}
  265. }
  266. )
  267. #service_category = tables.Column(
  268. service_category = tables.LinkColumn(
  269. 'sharix_admin:service_category/edit/',
  270. verbose_name=_('Название схемы услуги'),
  271. text=lambda record: record.service_category.caption,
  272. args=[tables.A('pk')],
  273. attrs={
  274. 'th': {'scope': 'col'},
  275. "td": {"width": "15%"}
  276. }
  277. )
  278. resource_type = tables.Column(
  279. verbose_name=_('Тип ресурса'),
  280. attrs={
  281. 'th': {'scope': 'col'},
  282. "td": {"width": "20%"}
  283. }
  284. )
  285. company_comission = tables.Column(
  286. verbose_name=_('Комиссия партнера'),
  287. attrs={
  288. 'th': {'scope': 'col'},
  289. "td": {"width": "20%"}
  290. }
  291. )
  292. check = tables.BooleanColumn(
  293. verbose_name=_('Activity'),
  294. orderable=False,
  295. attrs={
  296. 'th': {'scope': 'col'},
  297. "td": {"width": "20%"}
  298. }
  299. )
  300. class Meta:
  301. model = Service
  302. attrs = {
  303. "class": "table table-layout-fixed"
  304. }
  305. exclude = (
  306. 'resource',
  307. 'company',
  308. 'caption',
  309. 'description',
  310. 'price_type',
  311. 'price_min',
  312. 'price_amount',
  313. 'id_metaservice',
  314. 'requirements',
  315. 'ticket_status',
  316. 'price_km',
  317. 'is_global',
  318. 'is_visible',
  319. 'status'
  320. )
  321. def render_check(self, value, record):
  322. if record.status == 'active':
  323. return format_html('<input class="form-check-input status-toggle" disabled checked type="checkbox"')
  324. else:
  325. return format_html('<input class="form-check-input status-toggle" disabled type="checkbox"')
  326. class ServiceCategoriesTable(tables.Table):
  327. id = tables.Column(attrs={"td": {"width": "50px"}})
  328. caption = tables.LinkColumn(
  329. 'sharix_admin:service_category/edit/',
  330. verbose_name='Услуга',
  331. orderable=False,
  332. text=lambda record: record.caption,
  333. args=[tables.A('pk')],
  334. attrs={
  335. "a": {"style": "pointer-events: none;"},
  336. 'th': {'scope': 'col'},
  337. "td": {"class": "name_col"}
  338. }
  339. )
  340. #codename = tables.LinkColumn(
  341. # 'sharix_admin:service_category/edit/',
  342. # verbose_name='Тех.название',
  343. # orderable=False,
  344. # text=lambda record: record.codename,
  345. # args=[tables.A('pk')],
  346. # attrs={
  347. # "a": {"style": "pointer-events: none;"},
  348. # 'th': {'scope': 'col'},
  349. # "td": {"class": "name_col"}
  350. # }
  351. #)
  352. description = tables.LinkColumn(
  353. 'sharix_admin:service_category/edit/',
  354. orderable=False, verbose_name='Описание',
  355. text=lambda record: record.description,
  356. args=[tables.A('pk')],
  357. attrs={
  358. "a": {"style": "pointer-events: none;"},
  359. 'th': {'scope': 'col'},
  360. "td": {"class": "description_col"}
  361. }
  362. )
  363. metaservice_comission = tables.Column(
  364. verbose_name=_('Комиссия Сервиса'),
  365. attrs={
  366. 'th': {'scope': 'col'},
  367. "td": {"width": "15%"}}
  368. )
  369. edit = tables.LinkColumn(
  370. 'sharix_admin:service_category/edit/',
  371. verbose_name='',
  372. orderable=False,
  373. text="E",
  374. args=[tables.A('pk')],
  375. attrs={
  376. 'th': {'scope': 'col'},
  377. "td": {"class": "edit_col"}
  378. }
  379. )
  380. check = tables.BooleanColumn(
  381. verbose_name=_('Activity'),
  382. orderable=False,
  383. attrs={
  384. 'th': {'scope': 'col'},
  385. "td": {"width": "5%"}
  386. }
  387. )
  388. #TODO change to 'change status!'
  389. #deletee = tables.LinkColumn(
  390. # 'sharix_admin:service_category/delete/',
  391. # verbose_name='',
  392. # orderable=False,
  393. # text="D",
  394. # args=[tables.A('pk')],
  395. # attrs={
  396. # 'th': {'scope': 'col'},
  397. # "td": {"class": "delete_col"}
  398. # }
  399. #)
  400. class Meta:
  401. model = ServiceCategory
  402. attrs = {
  403. "class": "table table-layout-fixed text-start"
  404. }
  405. exclude = (
  406. 'requirements',
  407. 'price_type',
  408. 'status',
  409. 'ticket_status',
  410. 'id_metaservice',
  411. 'link_agreement',
  412. 'is_global',
  413. 'is_visible',
  414. 'codename',
  415. )
  416. def render_check(self, value, record):
  417. if record.status == '0':
  418. #if record.status == 'active':
  419. return format_html(
  420. '<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-service_category-id="{}">',
  421. record.id
  422. )
  423. #return format_html('<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-service_category-id="{}">')
  424. #return format_html('<input class="form-check-input status-toggle" disabled checked type="checkbox"')
  425. else:
  426. return format_html(
  427. '<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-service_category-id="{}">',
  428. record.id
  429. )
  430. #return format_html('<input class="form-check-input status-toggle" disabled type="checkbox"')
  431. # def render_delete(self, value, record):
  432. # return format_html('<a href="/service_category/delete" class="btn btn-outline-danger">_(Delete)</a>')
  433. # def render_name_operation(self, value, record):
  434. # return format_html("<a href='{}'>{}</a>", record.get_absolute_url(), value)
  435. class ServiceTable(tables.Table):
  436. id = tables.Column(
  437. verbose_name=_('ID'),
  438. attrs={
  439. "td": {"width": "5%"}
  440. }
  441. )
  442. service_category = tables.Column(
  443. verbose_name=_('Description of the service'),
  444. accessor='service_category.caption',
  445. attrs={
  446. 'th': {'scope': 'col'},
  447. "td": {"width": "20%"}}
  448. )
  449. # description = tables.Column(verbose_name='Название тарифа', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  450. # description = tables.Column(verbose_name='Описание строки тарифов', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  451. # price_type = tables.Column(verbose_name='Тип тарифа', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  452. price_km = tables.Column(
  453. verbose_name=_('Cost km.'),
  454. attrs={
  455. 'th': {'scope': 'col'},
  456. "td": {"width": "20%"}
  457. }
  458. )
  459. price_min = tables.Column(
  460. verbose_name=_('Cost min.'),
  461. attrs={
  462. 'th': {'scope': 'col'},
  463. "td": {"width": "20%"}}
  464. )
  465. price_amount = tables.Column(
  466. verbose_name=_('Cost of service'),
  467. attrs={
  468. 'th': {'scope': 'col'},
  469. "td": {"width": "20%"}
  470. }
  471. )
  472. class Meta:
  473. model = Service
  474. attrs = {
  475. "class": "table table-layout-fixed"
  476. }
  477. exclude = (
  478. 'resource',
  479. 'requirements',
  480. 'id_metaservice',
  481. 'price_type',
  482. 'ticket_status',
  483. 'is_global',
  484. 'is_visible'
  485. )
  486. def render_check(self, value, record):
  487. if record.status == 'active':
  488. return format_html(
  489. '<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-service-id="{}">',
  490. record.id
  491. )
  492. else:
  493. return format_html(
  494. '<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-service-id="{}">',
  495. record.id
  496. )
  497. class UserInfoTable(tables.Table):
  498. id = tables.Column(
  499. verbose_name=_('ID'),
  500. attrs={
  501. "td": {"width": "5%"}
  502. }
  503. )
  504. class Meta:
  505. model = get_user_model()
  506. attrs = {
  507. "class": "table table-layout-fixed"
  508. }
  509. exclude = (
  510. 'password',
  511. 'phone_number',
  512. 'last_login',
  513. 'is_staff',
  514. 'is_superuser',
  515. 'date_joined'
  516. )
  517. class PermissionsTable(tables.Table):
  518. id = tables.Column(
  519. verbose_name=_('ID'),
  520. attrs={
  521. "td": {"width": "5%"}
  522. }
  523. )
  524. user = tables.Column(
  525. accessor='user.full_name',
  526. order_by=('user.first_name', 'user.last_name'),
  527. verbose_name=_('User'),
  528. attrs={
  529. "td": {"width": "15%"}
  530. }
  531. )
  532. id_permissions = tables.Column(
  533. verbose_name=_('Permission'),
  534. attrs={
  535. "td": {"width": "15%"}
  536. }
  537. )
  538. status = tables.Column(
  539. verbose_name=_('Status'),
  540. attrs={
  541. 'th': {'scope': 'col'},
  542. "td": {"width": "20%"}
  543. }
  544. )
  545. check = tables.BooleanColumn(
  546. verbose_name='',
  547. attrs={
  548. 'th': {'scope': 'col'},
  549. "td": {"width": "20%"}
  550. }
  551. )
  552. # paginate_by = 10
  553. class Meta:
  554. model = Permissions
  555. attrs = {
  556. "class": "table table-layout-fixed"
  557. }
  558. exclude = (
  559. 'check_date',
  560. 'expire_date',
  561. 'check_level',
  562. 'checked_by',
  563. 'ticket_status'
  564. )
  565. def render_check(self, value, record):
  566. if record.status == 'active':
  567. return format_html(
  568. '<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-resource-id="{}">',
  569. record.id
  570. )
  571. else:
  572. return format_html(
  573. '<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-resource-id="{}">',
  574. record.id
  575. )
  576. class RelationshipTable(tables.Table):
  577. id = tables.Column(
  578. verbose_name=_('ID'),
  579. attrs={
  580. "td": {"width": "5%"}
  581. }
  582. )
  583. user_who = tables.Column(
  584. accessor='user_who.full_name',
  585. order_by=('user_who.first_name', 'user_who.last_name'),
  586. verbose_name=_('Initiator'),
  587. attrs={
  588. "td": {"width": "15%"}
  589. }
  590. )
  591. user_whom = tables.Column(
  592. accessor='user_whom.full_name',
  593. order_by=('user_whom.first_name', 'user_whom.last_name'),
  594. verbose_name=_('Goal'),
  595. attrs={
  596. "td": {"width": "15%"}
  597. }
  598. )
  599. neg_type = tables.Column(
  600. verbose_name=_('Neg Type'),
  601. attrs={
  602. 'th': {'scope': 'col'},
  603. "td": {"width": "20%"}
  604. }
  605. )
  606. status = tables.Column(
  607. verbose_name=_('Status'),
  608. attrs={
  609. 'th': {'scope': 'col'},
  610. "td": {"width": "20%"}
  611. }
  612. )
  613. check = tables.BooleanColumn(
  614. verbose_name='',
  615. attrs={
  616. 'th': {'scope': 'col'},
  617. "td": {"width": "20%"}
  618. }
  619. )
  620. paginate_by = 10
  621. class Meta:
  622. model = Relationship
  623. attrs = {
  624. "class": "table table-layout-fixed"
  625. }
  626. exclude = (
  627. 'ticket_status',
  628. )
  629. def render_check(self, value, record):
  630. if record.status == 'active':
  631. return format_html(
  632. '<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-provider-id="{}">',
  633. record.id
  634. )
  635. else:
  636. return format_html(
  637. '<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-provider-id="{}">',
  638. record.id
  639. )