tables.py 21 KB

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