1
0

tables.py 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  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 ResourceTable(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.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. 'resoure_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 ProviderTable(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 ServiceTariffTable(tables.Table):
  251. id = tables.Column(
  252. verbose_name=_('ID'),
  253. attrs={
  254. "td": {"width": "5%"}
  255. }
  256. )
  257. service_category = tables.LinkColumn(
  258. '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 ServiceCategoryTable(tables.Table):
  305. id = tables.Column(attrs={"td": {"width": "50px"}})
  306. codename = tables.LinkColumn(
  307. 'service_category/edit/',
  308. verbose_name='Услуга',
  309. orderable=False,
  310. text=lambda record: record.codename,
  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. description = tables.LinkColumn(
  319. 'service_category/edit/',
  320. orderable=False, verbose_name='Описание',
  321. text=lambda record: record.description,
  322. args=[tables.A('pk')],
  323. attrs={
  324. "a": {"style": "pointer-events: none;"},
  325. 'th': {'scope': 'col'},
  326. "td": {"class": "description_col"}
  327. }
  328. )
  329. edit = tables.LinkColumn(
  330. 'service_category/edit/',
  331. verbose_name='',
  332. orderable=False,
  333. text="E",
  334. args=[tables.A('pk')],
  335. attrs={
  336. 'th': {'scope': 'col'},
  337. "td": {"class": "edit_col"}
  338. }
  339. )
  340. deletee = tables.LinkColumn(
  341. 'service_category/delete/',
  342. verbose_name='',
  343. orderable=False,
  344. text="D",
  345. args=[tables.A('pk')],
  346. attrs={
  347. 'th': {'scope': 'col'},
  348. "td": {"class": "delete_col"}
  349. }
  350. )
  351. class Meta:
  352. model = ServiceCategory
  353. attrs = {
  354. "class": "table table-layout-fixed text-start"
  355. }
  356. exclude = (
  357. 'requirements',
  358. 'price_type',
  359. 'status',
  360. 'ticket_status',
  361. 'id_metaservice',
  362. 'link_agreement',
  363. 'is_global',
  364. 'is_visible',
  365. 'caption'
  366. )
  367. # def render_delete(self, value, record):
  368. # return format_html('<a href="/service_category/delete" class="btn btn-outline-danger">_(Delete)</a>')
  369. # def render_name_operation(self, value, record):
  370. # return format_html("<a href='{}'>{}</a>", record.get_absolute_url(), value)
  371. class ServiceTable(tables.Table):
  372. id = tables.Column(
  373. verbose_name=_('ID'),
  374. attrs={
  375. "td": {"width": "5%"}
  376. }
  377. )
  378. service_category = tables.Column(
  379. verbose_name=_('Description of the service'),
  380. accessor='service_category.caption',
  381. attrs={
  382. 'th': {'scope': 'col'},
  383. "td": {"width": "20%"}}
  384. )
  385. # description = tables.Column(verbose_name='Название тарифа', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  386. # description = tables.Column(verbose_name='Описание строки тарифов', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  387. # price_type = tables.Column(verbose_name='Тип тарифа', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
  388. price_km = tables.Column(
  389. verbose_name=_('Cost km.'),
  390. attrs={
  391. 'th': {'scope': 'col'},
  392. "td": {"width": "20%"}
  393. }
  394. )
  395. price_min = tables.Column(
  396. verbose_name=_('Cost min.'),
  397. attrs={
  398. 'th': {'scope': 'col'},
  399. "td": {"width": "20%"}}
  400. )
  401. price_amount = tables.Column(
  402. verbose_name=_('Cost of service'),
  403. attrs={
  404. 'th': {'scope': 'col'},
  405. "td": {"width": "20%"}
  406. }
  407. )
  408. class Meta:
  409. model = Service
  410. attrs = {
  411. "class": "table table-layout-fixed"
  412. }
  413. exclude = (
  414. 'resource',
  415. 'requirements',
  416. 'id_metaservice',
  417. 'price_type',
  418. 'ticket_status',
  419. 'is_global',
  420. 'is_visible'
  421. )
  422. def render_check(self, value, record):
  423. if record.status == 'active':
  424. return format_html(
  425. '<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-service-id="{}">',
  426. record.id
  427. )
  428. else:
  429. return format_html(
  430. '<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-service-id="{}">',
  431. record.id
  432. )
  433. class UserInfoTable(tables.Table):
  434. id = tables.Column(
  435. verbose_name=_('ID'),
  436. attrs={
  437. "td": {"width": "5%"}
  438. }
  439. )
  440. class Meta:
  441. model = get_user_model()
  442. attrs = {
  443. "class": "table table-layout-fixed"
  444. }
  445. exclude = (
  446. 'password',
  447. 'phone_number',
  448. 'last_login',
  449. 'is_staff',
  450. 'is_superuser',
  451. 'date_joined'
  452. )