tables.py 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  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 django_tables2.utils import A
  8. from sharix_admin.views import *
  9. from sharix_admin.urls import *
  10. class TransactionsWalletTable(tables.Table):
  11. # id = tables.Column(order_by=True)
  12. id = tables.Column(
  13. verbose_name='#',
  14. orderable=False,
  15. attrs={
  16. "td": {"width": "5%"}
  17. }
  18. )
  19. wallet = tables.Column(
  20. verbose_name=_('Owner'),
  21. orderable=False,
  22. attrs={
  23. "td": {"width": "15%"}
  24. }
  25. )
  26. name_operation = tables.Column(
  27. verbose_name=_('Service'),
  28. attrs={
  29. 'th': {'scope': 'col'},
  30. "td": {"width": "20%"}
  31. }
  32. )
  33. price = tables.Column(
  34. verbose_name=_('Points'),
  35. attrs={
  36. "class": "row",
  37. "td": {"width": "10%"}
  38. }
  39. )
  40. date_operation = tables.Column(
  41. verbose_name=_('Registration date'),
  42. attrs={
  43. "td": {"width": "30%"}
  44. }
  45. )
  46. is_carried_out = tables.BooleanColumn(
  47. verbose_name=_('Status'),
  48. orderable=False,
  49. yesno=_("Successful, not successful"),
  50. attrs={
  51. "td": {"width": "20%"}
  52. }
  53. )
  54. class Meta:
  55. # model = TransactionsWallets
  56. attrs = {
  57. "class": "table table-striped"
  58. }
  59. exclude = (
  60. "balance_before",
  61. "amount",
  62. "metaservice_id",
  63. "transaction_type",
  64. "doc_num",
  65. "service_id"
  66. )
  67. def render_name_operation(self, value, record):
  68. return format_html(
  69. "<a href='{}'>{}</a>",
  70. record.get_absolute_url(),
  71. value
  72. )
  73. class PartnersTable(tables.Table):
  74. id = tables.Column(
  75. verbose_name=_('ID'),
  76. attrs={
  77. "td": {"width": "5%"}
  78. }
  79. )
  80. legal_name = tables.Column(
  81. verbose_name=_('Legal entity'),
  82. attrs={
  83. 'th': {'scope': 'col'},
  84. "td": {"width": "20%"}
  85. }
  86. )
  87. repr = tables.Column(
  88. accessor='repr.full_name',
  89. order_by=('repr.first_name', 'repr.last_name'),
  90. verbose_name=_('Responsible'),
  91. attrs={
  92. "td": {"width": "15%"}
  93. }
  94. )
  95. status = tables.Column(
  96. verbose_name=_('Status'),
  97. attrs={
  98. 'th': {'scope': 'col'},
  99. "td": {"width": "20%"}
  100. }
  101. )
  102. check = tables.BooleanColumn(
  103. verbose_name='',
  104. attrs={
  105. 'th': {'scope': 'col'},
  106. "td": {"width": "20%"}
  107. }
  108. )
  109. # paginate_by = 10
  110. class Meta:
  111. model = Company
  112. attrs = {
  113. "class": "table table-layout-fixed"
  114. }
  115. exclude = (
  116. 'inn',
  117. 'kpp',
  118. 'ogrn',
  119. 'bank_name',
  120. 'bik',
  121. 'ks',
  122. 'rs',
  123. 'address',
  124. 'requirements',
  125. 'id_metaservice',
  126. 'is_global',
  127. 'is_visible',
  128. 'ticket_status'
  129. )
  130. def render_check(self, value, record):
  131. if record.status == 'active':
  132. return format_html(
  133. '<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-partners-id="{}">',
  134. record.id
  135. )
  136. else:
  137. return format_html(
  138. '<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-partners-id="{}">',
  139. record.id
  140. )
  141. class ResourceTable(tables.Table):
  142. id = tables.Column(
  143. verbose_name=_('ID'),
  144. attrs={
  145. "td": {"width": "5%"}
  146. }
  147. )
  148. # В user ссылка LinkColumn на страницу Аси "Информация о партнере" страница partner_information_form
  149. user = tables.Column(
  150. accessor='user.full_name',
  151. order_by=('user.first_name', 'user.last_name'),
  152. verbose_name=_('Responsible'),
  153. attrs={
  154. "td": {"width": "15%"}
  155. }
  156. )
  157. status = tables.Column(
  158. verbose_name=_('Status'),
  159. attrs={
  160. 'th': {'scope': 'col'},
  161. "td": {"width": "20%"}
  162. }
  163. )
  164. check = tables.BooleanColumn(
  165. verbose_name='',
  166. attrs={
  167. 'th': {'scope': 'col'},
  168. "td": {"width": "20%"}
  169. }
  170. )
  171. # paginate_by = 10
  172. class Meta:
  173. model = Resource
  174. attrs = {
  175. "class": "table table-layout-fixed"
  176. }
  177. exclude = (
  178. 'id_metaservice',
  179. 'resoure_type',
  180. 'requirements',
  181. 'is_global',
  182. 'is_visible',
  183. 'ticket_status'
  184. )
  185. def render_check(self, value, record):
  186. if record.status == 'active':
  187. return format_html(
  188. '<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-resource-id="{}">',
  189. record.id
  190. )
  191. else:
  192. return format_html(
  193. '<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-resource-id="{}">',
  194. record.id
  195. )
  196. class ProviderTable(tables.Table):
  197. id = tables.Column(
  198. verbose_name=_('ID'),
  199. attrs={
  200. "td": {"width": "5%"}
  201. }
  202. )
  203. user = tables.Column(
  204. accessor='user.full_name',
  205. order_by=('user.first_name', 'user.last_name'),
  206. verbose_name=_('Full Name'),
  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": "20%"}
  223. }
  224. )
  225. paginate_by = 10
  226. class Meta:
  227. model = Provider
  228. attrs = {
  229. "class": "table table-layout-fixed"
  230. }
  231. exclude = (
  232. 'type',
  233. 'company',
  234. 'id_metaservice',
  235. 'requirements',
  236. 'ticket_status',
  237. 'location_type',
  238. 'default_location',
  239. 'is_global',
  240. 'is_visible'
  241. )
  242. def render_check(self, value, record):
  243. if record.status == 'active':
  244. return format_html(
  245. '<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-provider-id="{}">',
  246. record.id
  247. )
  248. else:
  249. return format_html(
  250. '<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-provider-id="{}">',
  251. record.id
  252. )
  253. class ServiceTariffTable(tables.Table):
  254. id = tables.Column(
  255. verbose_name=_('ID'),
  256. attrs={
  257. "td": {"width": "5%"}
  258. }
  259. )
  260. servicetype = tables.LinkColumn(
  261. 'service_tariff/edit/',
  262. verbose_name=_('Name of the tariff'),
  263. text=lambda record: record.servicetype.caption,
  264. args=[tables.A('pk')],
  265. attrs={
  266. 'th': {'scope': 'col'},
  267. "td": {"width": "20%"}
  268. }
  269. )
  270. ticket_status = tables.Column(
  271. verbose_name=_('Name of the service scheme'),
  272. attrs={
  273. 'th': {'scope': 'col'},
  274. "td": {"width": "20%"}
  275. }
  276. )
  277. check = tables.BooleanColumn(
  278. verbose_name=_('Activity'),
  279. orderable=False,
  280. attrs={
  281. 'th': {'scope': 'col'},
  282. "td": {"width": "20%"}
  283. }
  284. )
  285. class Meta:
  286. model = Service
  287. attrs = {
  288. "class": "table table-layout-fixed"
  289. }
  290. exclude = (
  291. 'resource',
  292. 'price_alg',
  293. 'price_min',
  294. 'price_amount',
  295. 'id_metaservice',
  296. 'requirements',
  297. 'service_status',
  298. 'price_km',
  299. 'is_global',
  300. 'is_visible',
  301. 'status'
  302. )
  303. def render_check(self, value, record):
  304. if record.status == 'active':
  305. return format_html('<input class="form-check-input status-toggle" disabled checked type="checkbox"')
  306. else:
  307. return format_html('<input class="form-check-input status-toggle" disabled type="checkbox"')
  308. class ServiceTypeTable(tables.Table):
  309. id = tables.Column(attrs={"td": {"width": "50px"}})
  310. codename = tables.LinkColumn(
  311. 'service_type/edit/',
  312. verbose_name='Услуга',
  313. orderable=False,
  314. text=lambda record: record.codename,
  315. args=[tables.A('pk')],
  316. attrs={
  317. "a": {"style": "pointer-events: none;"},
  318. 'th': {'scope': 'col'},
  319. "td": {"class": "name_col"}
  320. }
  321. )
  322. description = tables.LinkColumn(
  323. 'service_type/edit/',
  324. orderable=False, verbose_name='Описание',
  325. text=lambda record: record.description,
  326. args=[tables.A('pk')],
  327. attrs={
  328. "a": {"style": "pointer-events: none;"},
  329. 'th': {'scope': 'col'},
  330. "td": {"class": "description_col"}
  331. }
  332. )
  333. edit = tables.LinkColumn(
  334. 'service_type/edit/',
  335. verbose_name='',
  336. orderable=False,
  337. text="E",
  338. args=[tables.A('pk')],
  339. attrs={
  340. 'th': {'scope': 'col'},
  341. "td": {"class": "edit_col"}
  342. }
  343. )
  344. deletee = tables.LinkColumn(
  345. 'service_type/delete/',
  346. verbose_name='',
  347. orderable=False,
  348. text="D",
  349. args=[tables.A('pk')],
  350. attrs={
  351. 'th': {'scope': 'col'},
  352. "td": {"class": "delete_col"}
  353. }
  354. )
  355. class Meta:
  356. model = ServiceType
  357. attrs = {
  358. "class": "table table-layout-fixed text-start"
  359. }
  360. exclude = (
  361. 'requirements',
  362. 'price_type',
  363. 'status',
  364. 'ticket_status',
  365. 'id_metaservice',
  366. 'link_agreement',
  367. 'is_global',
  368. 'is_visible',
  369. 'caption'
  370. )
  371. # def render_delete(self, value, record):
  372. # return format_html('<a href="/service_type/delete" class="btn btn-outline-danger">_(Delete)</a>')
  373. # def render_name_operation(self, value, record):
  374. # return format_html("<a href='{}'>{}</a>", record.get_absolute_url(), value)
  375. class ServiceTable(tables.Table):
  376. id = tables.Column(
  377. verbose_name=_('id'),
  378. attrs={
  379. "td": {"width": "5%"}
  380. }
  381. )
  382. servicetype = tables.Column(
  383. verbose_name=_('Услуга'),
  384. accessor='servicetype.caption',
  385. attrs={
  386. 'th': {'scope': 'col'},
  387. "td": {"width": "20%"}}
  388. )
  389. servicedescription = tables.Column(
  390. verbose_name=_('Описание'),
  391. accessor='servicetype.description',
  392. attrs={
  393. 'th': {'scope': 'col'},
  394. "td": {"width": "40%"}}
  395. )
  396. # description = tables.Column(verbose_name='Название тарифа', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  397. # description = tables.Column(verbose_name='Описание строки тарифов', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  398. # price_type = tables.Column(verbose_name='Тип тарифа', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  399. price_km = tables.Column(
  400. verbose_name=_('Cost km.'),
  401. attrs={
  402. 'th': {'scope': 'col'},
  403. "td": {"width": "20%"}
  404. }
  405. )
  406. price_min = tables.Column(
  407. verbose_name=_('Cost min.'),
  408. attrs={
  409. 'th': {'scope': 'col'},
  410. "td": {"width": "20%"}}
  411. )
  412. price_amount = tables.Column(
  413. verbose_name=_('Cost of service'),
  414. attrs={
  415. 'th': {'scope': 'col'},
  416. "td": {"width": "20%"}
  417. }
  418. )
  419. edit = tables.LinkColumn("sharix_admin:service_edit", text=lambda record:record.id,
  420. attrs={
  421. 'th': {'scope': 'col'},
  422. "td": {"width": "10%"}
  423. })
  424. class Meta:
  425. model = Service
  426. attrs = {
  427. "class": "table table-layout-fixed"
  428. }
  429. exclude = (
  430. 'company_comission',
  431. 'price_amount',
  432. 'price_min',
  433. 'price_km',
  434. 'resource',
  435. 'requirements',
  436. 'id_metaservice',
  437. 'price_alg',
  438. 'service_status',
  439. 'ticket_status',
  440. 'is_global',
  441. 'is_visible'
  442. )
  443. def render_check(self, value, record):
  444. if record.status == 'active':
  445. return format_html(
  446. '<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-service-id="{}">',
  447. record.id
  448. )
  449. else:
  450. return format_html(
  451. '<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-service-id="{}">',
  452. record.id
  453. )
  454. class UserInfoTable(tables.Table):
  455. id = tables.Column(
  456. verbose_name=_('ID'),
  457. attrs={
  458. "td": {"width": "5%"}
  459. }
  460. )
  461. class Meta:
  462. model = get_user_model()
  463. attrs = {
  464. "class": "table table-layout-fixed"
  465. }
  466. exclude = (
  467. 'password',
  468. 'phone_number',
  469. 'last_login',
  470. 'is_staff',
  471. 'is_superuser',
  472. 'date_joined'
  473. )