tables.py 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  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 OrdersTable(tables.Table):
  139. id = tables.Column(
  140. verbose_name=_('ID'),
  141. attrs={
  142. "td": {"width": "5%"}
  143. }
  144. )
  145. title = tables.Column(
  146. verbose_name=_('Title'),
  147. attrs={
  148. "td": {"width": "20%"}
  149. }
  150. )
  151. status = tables.Column(
  152. verbose_name=_('Status'),
  153. attrs={
  154. "td": {"width": "15%"}
  155. }
  156. )
  157. receiver = tables.Column(
  158. accessor='receiver.get_full_name',
  159. verbose_name=_('Receiver'),
  160. attrs={
  161. "td": {"width": "20%"}
  162. }
  163. )
  164. time_created = tables.DateTimeColumn(
  165. verbose_name=_('Created'),
  166. attrs={
  167. "td": {"width": "20%"}
  168. }
  169. )
  170. class Meta:
  171. model = Orders
  172. attrs = {
  173. "class": "table table-layout-fixed"
  174. }
  175. exclude = (
  176. 'id_metaservice',
  177. 'note',
  178. 'time_placed',
  179. 'time_start',
  180. 'time_start_real',
  181. 'time_start_predicted',
  182. 'time_finish_real',
  183. 'time_finish_predicted',
  184. 'real_price',
  185. 'predicted_price',
  186. 'asap',
  187. 'is_global',
  188. 'is_visible',
  189. 'ticket',
  190. 'service',
  191. 'service_category',
  192. 'client',
  193. 'provider',
  194. 'company')
  195. class ResourcesTable(tables.Table):
  196. id = tables.Column(
  197. verbose_name=_('ID'),
  198. attrs={
  199. "td": {"width": "5%"}
  200. }
  201. )
  202. # В user ссылка LinkColumn на страницу Аси "Информация о партнере" страница partner_information_form
  203. user = tables.Column(
  204. accessor='user.get_full_name',
  205. order_by=('user.first_name', 'user.last_name'),
  206. verbose_name=_('Responsible'),
  207. attrs={
  208. "td": {"width": "15%"}
  209. }
  210. )
  211. status = tables.Column(
  212. verbose_name=_('Status'),
  213. attrs={
  214. 'th': {'scope': 'col'},
  215. "td": {"width": "20%"}
  216. }
  217. )
  218. check = tables.BooleanColumn(
  219. verbose_name='',
  220. attrs={
  221. 'th': {'scope': 'col'},
  222. "td": {"width": "40%"}
  223. }
  224. )
  225. # paginate_by = 10
  226. class Meta:
  227. model = Resource
  228. attrs = {
  229. "class": "table table-layout-fixed"
  230. }
  231. exclude = (
  232. 'id_metaservice',
  233. 'resource_type',
  234. 'requirements',
  235. 'is_global',
  236. 'is_visible',
  237. 'ticket_status'
  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-resource-id="{}">',
  243. record.id
  244. )
  245. else:
  246. return format_html(
  247. '<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-resource-id="{}">',
  248. record.id
  249. )
  250. class ProvidersTable(tables.Table):
  251. id = tables.Column(
  252. verbose_name=_('ID'),
  253. attrs={
  254. "td": {"width": "5%"}
  255. }
  256. )
  257. user = tables.Column(
  258. accessor='user.full_name',
  259. order_by=('user.first_name', 'user.last_name'),
  260. verbose_name=_('Full Name'),
  261. attrs={
  262. "td": {"width": "15%"}
  263. }
  264. )
  265. status = tables.Column(
  266. verbose_name=_('Status'),
  267. attrs={
  268. 'th': {'scope': 'col'},
  269. "td": {"width": "20%"}
  270. }
  271. )
  272. check = tables.BooleanColumn(
  273. verbose_name='',
  274. attrs={
  275. 'th': {'scope': 'col'},
  276. "td": {"width": "20%"}
  277. }
  278. )
  279. paginate_by = 10
  280. class Meta:
  281. model = Provider
  282. attrs = {
  283. "class": "table table-layout-fixed"
  284. }
  285. exclude = (
  286. 'id_metaservice',
  287. 'gap',
  288. 'requirements',
  289. 'status',
  290. 'service_status',
  291. 'location_type',
  292. 'default_location',
  293. 'is_global',
  294. 'is_visible'
  295. )
  296. def render_check(self, value, record):
  297. if record.status == 'active':
  298. return format_html(
  299. '<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-provider-id="{}">',
  300. record.id
  301. )
  302. else:
  303. return format_html(
  304. '<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-provider-id="{}">',
  305. record.id
  306. )
  307. class ServiceTariffsTable(tables.Table):
  308. id = tables.Column(
  309. verbose_name=_('ID'),
  310. attrs={
  311. "td": {"width": "5%"}
  312. }
  313. )
  314. codename = tables.LinkColumn(
  315. 'sharix_admin:service_tariff/edit/',
  316. verbose_name=_('Кодовое название'),
  317. text=lambda record: record.caption,
  318. args=[tables.A('pk')],
  319. attrs={
  320. 'th': {'scope': 'col'},
  321. "td": {"width": "15%"}
  322. }
  323. )
  324. #service_category = tables.Column(
  325. service_category = tables.LinkColumn(
  326. 'sharix_admin:service_category/edit/',
  327. verbose_name=_('Название схемы услуги'),
  328. text=lambda record: record.service_category.caption,
  329. args=[tables.A('pk')],
  330. attrs={
  331. 'th': {'scope': 'col'},
  332. "td": {"width": "15%"}
  333. }
  334. )
  335. resource_type = tables.Column(
  336. verbose_name=_('Тип ресурса'),
  337. attrs={
  338. 'th': {'scope': 'col'},
  339. "td": {"width": "20%"}
  340. }
  341. )
  342. company_comission = tables.Column(
  343. verbose_name=_('Комиссия партнера'),
  344. attrs={
  345. 'th': {'scope': 'col'},
  346. "td": {"width": "20%"}
  347. }
  348. )
  349. check = tables.BooleanColumn(
  350. verbose_name=_('Activity'),
  351. orderable=False,
  352. attrs={
  353. 'th': {'scope': 'col'},
  354. "td": {"width": "20%"}
  355. }
  356. )
  357. class Meta:
  358. model = Service
  359. attrs = {
  360. "class": "table table-layout-fixed"
  361. }
  362. exclude = (
  363. 'resource',
  364. 'company',
  365. 'caption',
  366. 'description',
  367. 'price_type',
  368. 'price_min',
  369. 'price_amount',
  370. 'id_metaservice',
  371. 'requirements',
  372. 'ticket_status',
  373. 'price_km',
  374. 'is_global',
  375. 'is_visible',
  376. 'status'
  377. )
  378. def render_check(self, value, record):
  379. if record.status == 'active':
  380. return format_html('<input class="form-check-input status-toggle" disabled checked type="checkbox"')
  381. else:
  382. return format_html('<input class="form-check-input status-toggle" disabled type="checkbox"')
  383. class ServiceCategoriesTable(tables.Table):
  384. id = tables.Column(attrs={"td": {"width": "50px"}})
  385. caption = tables.LinkColumn(
  386. 'sharix_admin:service_category/edit/',
  387. verbose_name='Услуга',
  388. orderable=False,
  389. text=lambda record: record.caption,
  390. args=[tables.A('pk')],
  391. attrs={
  392. "a": {"style": "pointer-events: none;"},
  393. 'th': {'scope': 'col'},
  394. "td": {"class": "name_col"}
  395. }
  396. )
  397. #codename = tables.LinkColumn(
  398. # 'sharix_admin:service_category/edit/',
  399. # verbose_name='Тех.название',
  400. # orderable=False,
  401. # text=lambda record: record.codename,
  402. # args=[tables.A('pk')],
  403. # attrs={
  404. # "a": {"style": "pointer-events: none;"},
  405. # 'th': {'scope': 'col'},
  406. # "td": {"class": "name_col"}
  407. # }
  408. #)
  409. description = tables.LinkColumn(
  410. 'sharix_admin:service_category/edit/',
  411. orderable=False, verbose_name='Описание',
  412. text=lambda record: record.description,
  413. args=[tables.A('pk')],
  414. attrs={
  415. "a": {"style": "pointer-events: none;"},
  416. 'th': {'scope': 'col'},
  417. "td": {"class": "description_col"}
  418. }
  419. )
  420. metaservice_comission = tables.Column(
  421. verbose_name=_('Комиссия Сервиса'),
  422. attrs={
  423. 'th': {'scope': 'col'},
  424. "td": {"width": "15%"}}
  425. )
  426. edit = tables.LinkColumn(
  427. 'sharix_admin:service_category/edit/',
  428. verbose_name='',
  429. orderable=False,
  430. text="E",
  431. args=[tables.A('pk')],
  432. attrs={
  433. 'th': {'scope': 'col'},
  434. "td": {"class": "edit_col"}
  435. }
  436. )
  437. check = tables.BooleanColumn(
  438. verbose_name=_('Activity'),
  439. orderable=False,
  440. attrs={
  441. 'th': {'scope': 'col'},
  442. "td": {"width": "5%"}
  443. }
  444. )
  445. #TODO change to 'change status!'
  446. #deletee = tables.LinkColumn(
  447. # 'sharix_admin:service_category/delete/',
  448. # verbose_name='',
  449. # orderable=False,
  450. # text="D",
  451. # args=[tables.A('pk')],
  452. # attrs={
  453. # 'th': {'scope': 'col'},
  454. # "td": {"class": "delete_col"}
  455. # }
  456. #)
  457. class Meta:
  458. model = ServiceCategory
  459. attrs = {
  460. "class": "table table-layout-fixed text-start"
  461. }
  462. exclude = (
  463. 'requirements',
  464. 'price_type',
  465. 'status',
  466. 'ticket_status',
  467. 'id_metaservice',
  468. 'link_agreement',
  469. 'is_global',
  470. 'is_visible',
  471. 'codename',
  472. )
  473. def render_check(self, value, record):
  474. if record.status == '0':
  475. #if record.status == 'active':
  476. return format_html(
  477. '<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-service_category-id="{}">',
  478. record.id
  479. )
  480. #return format_html('<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-service_category-id="{}">')
  481. #return format_html('<input class="form-check-input status-toggle" disabled checked type="checkbox"')
  482. else:
  483. return format_html(
  484. '<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-service_category-id="{}">',
  485. record.id
  486. )
  487. #return format_html('<input class="form-check-input status-toggle" disabled type="checkbox"')
  488. # def render_delete(self, value, record):
  489. # return format_html('<a href="/service_category/delete" class="btn btn-outline-danger">_(Delete)</a>')
  490. # def render_name_operation(self, value, record):
  491. # return format_html("<a href='{}'>{}</a>", record.get_absolute_url(), value)
  492. class ServiceTable(tables.Table):
  493. id = tables.Column(
  494. verbose_name=_('ID'),
  495. attrs={
  496. "td": {"width": "5%"}
  497. }
  498. )
  499. service_category = tables.Column(
  500. verbose_name=_('Description of the service'),
  501. accessor='service_category.caption',
  502. attrs={
  503. 'th': {'scope': 'col'},
  504. "td": {"width": "20%"}}
  505. )
  506. # description = tables.Column(verbose_name='Название тарифа', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  507. # description = tables.Column(verbose_name='Описание строки тарифов', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  508. # price_type = tables.Column(verbose_name='Тип тарифа', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  509. price_km = tables.Column(
  510. verbose_name=_('Cost km.'),
  511. attrs={
  512. 'th': {'scope': 'col'},
  513. "td": {"width": "20%"}
  514. }
  515. )
  516. price_min = tables.Column(
  517. verbose_name=_('Cost min.'),
  518. attrs={
  519. 'th': {'scope': 'col'},
  520. "td": {"width": "20%"}}
  521. )
  522. price_amount = tables.Column(
  523. verbose_name=_('Cost of service'),
  524. attrs={
  525. 'th': {'scope': 'col'},
  526. "td": {"width": "20%"}
  527. }
  528. )
  529. class Meta:
  530. model = Service
  531. attrs = {
  532. "class": "table table-layout-fixed"
  533. }
  534. exclude = (
  535. 'resource',
  536. 'requirements',
  537. 'id_metaservice',
  538. 'price_type',
  539. 'ticket_status',
  540. 'is_global',
  541. 'is_visible'
  542. )
  543. def render_check(self, value, record):
  544. if record.status == 'active':
  545. return format_html(
  546. '<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-service-id="{}">',
  547. record.id
  548. )
  549. else:
  550. return format_html(
  551. '<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-service-id="{}">',
  552. record.id
  553. )
  554. class UserInfoTable(tables.Table):
  555. id = tables.Column(
  556. verbose_name=_('ID'),
  557. attrs={
  558. "td": {"width": "5%"}
  559. }
  560. )
  561. class Meta:
  562. model = get_user_model()
  563. attrs = {
  564. "class": "table table-layout-fixed"
  565. }
  566. exclude = (
  567. 'password',
  568. 'phone_number',
  569. 'last_login',
  570. 'is_staff',
  571. 'is_superuser',
  572. 'date_joined'
  573. )
  574. class PermissionsTable(tables.Table):
  575. id = tables.Column(
  576. verbose_name=_('ID'),
  577. attrs={
  578. "td": {"width": "5%"}
  579. }
  580. )
  581. user = tables.Column(
  582. accessor='user.full_name',
  583. order_by=('user.first_name', 'user.last_name'),
  584. verbose_name=_('User'),
  585. attrs={
  586. "td": {"width": "15%"}
  587. }
  588. )
  589. id_permissions = tables.Column(
  590. verbose_name=_('Permission'),
  591. attrs={
  592. "td": {"width": "15%"}
  593. }
  594. )
  595. status = tables.Column(
  596. verbose_name=_('Status'),
  597. attrs={
  598. 'th': {'scope': 'col'},
  599. "td": {"width": "20%"}
  600. }
  601. )
  602. check = tables.BooleanColumn(
  603. verbose_name='',
  604. attrs={
  605. 'th': {'scope': 'col'},
  606. "td": {"width": "20%"}
  607. }
  608. )
  609. # paginate_by = 10
  610. class Meta:
  611. model = Permissions
  612. attrs = {
  613. "class": "table table-layout-fixed"
  614. }
  615. exclude = (
  616. 'check_date',
  617. 'expire_date',
  618. 'check_level',
  619. 'checked_by',
  620. 'ticket_status'
  621. )
  622. def render_check(self, value, record):
  623. if record.status == 'active':
  624. return format_html(
  625. '<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-resource-id="{}">',
  626. record.id
  627. )
  628. else:
  629. return format_html(
  630. '<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-resource-id="{}">',
  631. record.id
  632. )
  633. class RelationshipTable(tables.Table):
  634. id = tables.Column(
  635. verbose_name=_('ID'),
  636. attrs={
  637. "td": {"width": "5%"}
  638. }
  639. )
  640. user_who = tables.Column(
  641. accessor='user_who.full_name',
  642. order_by=('user_who.first_name', 'user_who.last_name'),
  643. verbose_name=_('Initiator'),
  644. attrs={
  645. "td": {"width": "15%"}
  646. }
  647. )
  648. user_whom = tables.Column(
  649. accessor='user_whom.full_name',
  650. order_by=('user_whom.first_name', 'user_whom.last_name'),
  651. verbose_name=_('Goal'),
  652. attrs={
  653. "td": {"width": "15%"}
  654. }
  655. )
  656. neg_type = tables.Column(
  657. verbose_name=_('Neg Type'),
  658. attrs={
  659. 'th': {'scope': 'col'},
  660. "td": {"width": "20%"}
  661. }
  662. )
  663. status = tables.Column(
  664. verbose_name=_('Status'),
  665. attrs={
  666. 'th': {'scope': 'col'},
  667. "td": {"width": "20%"}
  668. }
  669. )
  670. check = tables.BooleanColumn(
  671. verbose_name='',
  672. attrs={
  673. 'th': {'scope': 'col'},
  674. "td": {"width": "20%"}
  675. }
  676. )
  677. paginate_by = 10
  678. class Meta:
  679. model = Relationship
  680. attrs = {
  681. "class": "table table-layout-fixed"
  682. }
  683. exclude = (
  684. 'ticket_status',
  685. )
  686. def render_check(self, value, record):
  687. if record.status == 'active':
  688. return format_html(
  689. '<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-provider-id="{}">',
  690. record.id
  691. )
  692. else:
  693. return format_html(
  694. '<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-provider-id="{}">',
  695. record.id
  696. )