tables.py 20 KB

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