tables.py 21 KB

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