tables.py 18 KB

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