views_old.py 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. from django.shortcuts import render
  2. from django.http import HttpResponseRedirect, HttpResponse, JsonResponse
  3. from django.contrib.auth.views import LoginView
  4. from django.urls import reverse_lazy, resolve, reverse
  5. from django.contrib.auth.decorators import login_required
  6. from django_tables2 import SingleTableView
  7. from metaservicesynced.models import *
  8. from .forms import *
  9. from SharixAdmin.models import *
  10. from django.contrib.auth import logout
  11. from django.db.models import Q
  12. from django_tables2 import SingleTableView
  13. from .tables import *
  14. from django import template
  15. from django.views.generic.edit import UpdateView, CreateView
  16. from django.core import serializers
  17. from django_tables2 import SingleTableView
  18. from django.views.generic.edit import UpdateView, CreateView, DeleteView
  19. # Create your views here.
  20. # @login_required
  21. # def index(request):
  22. # ph_num = str(request.user.phone_number)
  23. # convert_ph_num = f"+{ph_num[:1]} ({ph_num[1:4]}) {ph_num[4:7]}-{ph_num[7:9]}-{ph_num[9:11]}"
  24. # #print(convert_ph_num)
  25. # context = get_context(request, {
  26. # 'title':'Главная/баланс',
  27. # 'phone':convert_ph_num
  28. # })
  29. # return render(request, 'SharixAdmin/main.html', context)
  30. # @login_required
  31. # def transactions(request):
  32. # context = get_context(request, {
  33. # 'title':'История платежей',
  34. # })
  35. # return render(request, 'SharixAdmin/transactions.html', context)
  36. @login_required
  37. def servicetype(request):
  38. service_types = ServiceType.objects.all()
  39. context = get_context(request, {
  40. 'title':'Услуги сервиса',
  41. 'service_types':service_types,
  42. })
  43. return render(request, 'SharixAdmin/servicetype.html', context)
  44. @login_required
  45. def trans_id(request, trans_id):
  46. context = get_context(request, {
  47. 'title':'Услуга'
  48. })
  49. return render(request, 'SharixAdmin/trans_carried.html', context)
  50. @login_required
  51. def balance(request):
  52. context = get_context(request, {
  53. 'title':'Пополнить баланс'
  54. })
  55. if request.method == 'POST':
  56. if float(request.POST['price']) > 0:
  57. context = get_context(request, {
  58. 'title':'Пополнить баланс',
  59. 'msg':'Оплата прошла успешно ;)'
  60. })
  61. return render(request, "SharixAdmin/balance_success.html", context)
  62. else:
  63. context = get_context(request, {
  64. 'title':'Пополнить баланс',
  65. 'msg':'Оплата не прошла ;('
  66. })
  67. return render(request, "SharixAdmin/balance_success.html", context)
  68. return render(request, "SharixAdmin/balance.html", context)
  69. def logout_view(request):
  70. logout(request)
  71. return HttpResponseRedirect(reverse('authweb'))
  72. class LoginSharix(LoginView):
  73. form_class = LoginUserForm
  74. template_name = 'SharixAdmin/auth.html'
  75. def get_success_url(self):
  76. print(self.request.GET['next'])
  77. return reverse_lazy('home')
  78. def testPage(request):
  79. context = get_context(request, {
  80. 'title':'Страница в разработке'
  81. })
  82. return render(request, "SharixAdmin/test.html", context)
  83. menu = [
  84. {'title':'Главная/баланс', 'link':'home', 'sel':'house'},
  85. {'title':'Платежная информация', 'link':'test-page', 'sel':'credit-card'},
  86. {'title':'История платежей', 'link':'trans','sel':'clock-history'},
  87. {'title':'Курсы', 'link':'course', 'sel':'education'},
  88. {'title':'Личная информация', 'link':'test-page', 'sel':'person'},
  89. {'title':'Управление сервисами', 'link':'test-page', 'sel':'hdd-network'},
  90. {'title':'Мои связи', 'link':'test-page', 'sel':'people'},
  91. {'title':'Сотрудничество', 'link':'test-page', 'sel':'sotrud'},
  92. {'title':'Техподдержка', 'link':'test-page', 'sel':'gear'},
  93. {'title':'Мои заявки', 'link':'tickets', 'sel':'tikets'},
  94. {'title':'Исполнители', 'link':'provider', 'sel':'people'},
  95. {'title':'Тарифы услуг', 'link':'service_tariff', 'sel':'person'},
  96. {'title':'Партнеры', 'link':'partners', 'sel':'people'},
  97. {'title':'Ресурсы', 'link':'resource', 'sel':'sotrud'},
  98. {'title':'Услуги сервиса', 'link':'service_type', 'sel':'hdd-network'},
  99. {'title':'Информация о сервисе', 'link':'partner_information/add/', 'sel':'hdd-network'},
  100. {'title':'Информация о партнере', 'link':'partner_information/add/', 'sel':'person'},
  101. {'title':'Тарифы', 'link':'service', 'sel':'tikets'},
  102. ]
  103. def partner_information(request):
  104. context = get_context(request, {
  105. 'title':'Информация о партнере',
  106. })
  107. return render(request, 'SharixAdmin/partner_information.html', context)
  108. def get_context(request, page_context) -> dict:
  109. base_context = {
  110. "title":page_context['title'],
  111. 'url_path':resolve(request.path_info).url_name,
  112. 'menu':menu
  113. }
  114. context = dict(list(base_context.items()) + list(page_context.items()))
  115. return context
  116. class PartnersListView(SingleTableView):
  117. table_class = PartnersTable
  118. queryset = Company.objects.all()
  119. template_name = 'SharixAdmin/partners.html'
  120. def get_context_data(self, **kwargs):
  121. context = super().get_context_data(**kwargs)
  122. context.update(get_context(self.request, {
  123. 'title': 'Партнеры',
  124. 'object_list': context['object_list'],
  125. }))
  126. return context
  127. @login_required
  128. def change_provider_status(request):
  129. if request.method == 'POST':
  130. provider_id = request.POST.get('provider_id')
  131. new_status = request.POST.get('new_status')
  132. provider = Provider.objects.get(pk=provider_id)
  133. provider.status = new_status
  134. provider.save()
  135. return JsonResponse({'status': 'success'})
  136. else:
  137. return JsonResponse({'status': 'error'})
  138. class ServiceTariffUpdateView(UpdateView):
  139. model = Service
  140. form_class = ServiceTariffUpdateForm
  141. template_name = "SharixAdmin/service_tariff_form.html"
  142. def get_context_data(self, **kwargs):
  143. context = super().get_context_data(**kwargs)
  144. context.update(get_context(self.request, {
  145. 'title': 'Тарифы услуг',
  146. 'object': self.object,
  147. }))
  148. return context
  149. def get_success_url(self):
  150. return reverse('service_tariff')
  151. class ServiceTariffCreate(CreateView):
  152. model = Service
  153. form_class = ServiceTariffCreateForm
  154. template_name = "SharixAdmin/service_tariff_form.html"
  155. def get_context_data(self, **kwargs):
  156. context = super().get_context_data(**kwargs)
  157. context.update(get_context(self.request, {
  158. 'title': 'Тарифы услуг',
  159. 'object': self.object,
  160. }))
  161. return context
  162. def get_success_url(self):
  163. return reverse('service_tariff')
  164. class ProviderListView(SingleTableView):
  165. table_class = ProviderTable
  166. queryset = Provider.objects.all()
  167. template_name = 'SharixAdmin/provider.html'
  168. def get_context_data(self, **kwargs):
  169. context = super().get_context_data(**kwargs)
  170. context.update(get_context(self.request, {
  171. 'title': 'Исполнители',
  172. 'object_list': context['object_list'],
  173. }))
  174. return context
  175. class ServiceTariffListView(SingleTableView):
  176. table_class = ServiceTariffTable
  177. queryset = Service.objects.all()
  178. template_name = 'SharixAdmin/service_tariff.html'
  179. # paginate_by = 2
  180. def get_context_data(self, **kwargs):
  181. context = super().get_context_data(**kwargs)
  182. context.update(get_context(self.request, {
  183. 'title': 'Исполнители',
  184. 'object_list': context['object_list'],
  185. }))
  186. return context
  187. class ServiceTypeUpdateView(UpdateView):
  188. model = ServiceType
  189. form_class = ServiceTypeUpdateForm
  190. template_name = "SharixAdmin/service_type_form.html"
  191. def get_context_data(self, **kwargs):
  192. context = super().get_context_data(**kwargs)
  193. context.update(get_context(self.request, {
  194. 'title': 'Тарифы услуг',
  195. 'object_list': context['object_list'],
  196. }))
  197. return context
  198. class ResourceListView(SingleTableView):
  199. table_class = ResourceTable
  200. queryset = Resource.objects.all()
  201. template_name = 'SharixAdmin/resource.html'
  202. def get_context_data(self, **kwargs):
  203. context = super().get_context_data(**kwargs)
  204. context.update(get_context(self.request, {
  205. 'title': 'Ресурсы',
  206. 'object_list': context['object_list'],
  207. }))
  208. return context
  209. class ServiceTypeCreate(CreateView):
  210. model = ServiceType
  211. form_class = ServiceTypeCreateForm
  212. template_name = "SharixAdmin/service_type_form.html"
  213. def get_context_data(self, **kwargs):
  214. context = super().get_context_data(**kwargs)
  215. context.update(get_context(self.request, {
  216. 'title': 'Услуги сервиса',
  217. 'object': self.object,
  218. }))
  219. return context
  220. def get_success_url(self):
  221. return reverse('service_type')
  222. @login_required
  223. def change_partners_status(request):
  224. if request.method == 'POST':
  225. partners_id = request.POST.get('partners_id')
  226. new_status = request.POST.get('new_status')
  227. partners = Company.objects.get(pk=partners_id)
  228. partners.status = new_status
  229. partners.save()
  230. return JsonResponse({'status': 'success'})
  231. else:
  232. return JsonResponse({'status': 'error'})
  233. @login_required
  234. def change_resource_status(request):
  235. if request.method == 'POST':
  236. resource_id = request.POST.get('resource_id')
  237. new_status = request.POST.get('new_status')
  238. resource = Resource.objects.get(pk=resource_id)
  239. resource.status = new_status
  240. resource.save()
  241. return JsonResponse({'status': 'success'})
  242. else:
  243. return JsonResponse({'status': 'error'})
  244. class ServiceTypeDelete(DeleteView):
  245. model = ServiceType
  246. template_name = "SharixAdmin/service_type_delete.html"
  247. def get_context_data(self, **kwargs):
  248. context = super().get_context_data(**kwargs)
  249. context.update(get_context(self.request, {
  250. 'title': 'Услуги сервиса',
  251. 'object': self.object,
  252. }))
  253. return context
  254. def get_success_url(self):
  255. return reverse('service_type')
  256. class ServiceTypeListView(SingleTableView):
  257. table_class = ServiceTypeTable
  258. queryset = ServiceType.objects.all()
  259. template_name = 'SharixAdmin/service_type.html'
  260. # paginate_by = 2
  261. def get_context_data(self, **kwargs):
  262. context = super().get_context_data(**kwargs)
  263. context.update(get_context(self.request, {
  264. 'title': 'Услуги сервиса',
  265. 'object_list': context['object_list'],
  266. }))
  267. return context
  268. class ServiceInformationUpdateView(UpdateView):
  269. model = Service
  270. form_class = ServiceInformationUpdateForm
  271. template_name = "SharixAdmin/service_information_form.html"
  272. def get_context_data(self, **kwargs):
  273. context = super().get_context_data(**kwargs)
  274. context.update(get_context(self.request, {
  275. 'title': 'Информация о сервисе',
  276. 'object': self.object,
  277. }))
  278. return context
  279. def get_success_url(self):
  280. return reverse('test-page')
  281. class ServiceInformationCreate(CreateView):
  282. model = Service
  283. form_class = ServiceInformationCreateForm
  284. template_name = "SharixAdmin/service_information_form.html"
  285. def get_context_data(self, **kwargs):
  286. context = super().get_context_data(**kwargs)
  287. context.update(get_context(self.request, {
  288. 'title': 'Информация о сервисе',
  289. 'object': self.object,
  290. }))
  291. return context
  292. def get_success_url(self):
  293. return reverse('test-page')
  294. class ServiceListView(SingleTableView):
  295. table_class = ServiceTable
  296. queryset = Service.objects.all()
  297. template_name = 'SharixAdmin/service.html'
  298. def get_context_data(self, **kwargs):
  299. context = super().get_context_data(**kwargs)
  300. context.update(get_context(self.request, {
  301. 'title': 'Тарифы',
  302. 'object_list': context['object_list'],
  303. }))
  304. return context
  305. @login_required
  306. def change_service_status(request):
  307. if request.method == 'POST':
  308. service_id = request.POST.get('service_id')
  309. new_status = request.POST.get('new_status')
  310. service = Service.objects.get(pk=service_id)
  311. service.status = new_status
  312. service.save()
  313. #Shema views
  314. @login_required
  315. def schema_v3(request):
  316. return render(request, "SharixAdmin/schema.html")
  317. class PartnerInformationUpdateView(UpdateView):
  318. model = Company
  319. form_class = PartnerInformationUpdateForm
  320. template_name = "SharixAdmin/partner_information_form.html"
  321. def get_context_data(self, **kwargs):
  322. context = super().get_context_data(**kwargs)
  323. context.update(get_context(self.request, {
  324. 'title': 'Информация о партнере',
  325. 'object': self.object,
  326. }))
  327. return context
  328. def get_success_url(self):
  329. return reverse('test-page')
  330. class PartnerInformationCreate(CreateView):
  331. model = Company
  332. form_class = PartnerInformationCreateForm
  333. template_name = "SharixAdmin/partner_information_form.html"
  334. def get_context_data(self, **kwargs):
  335. context = super().get_context_data(**kwargs)
  336. context.update(get_context(self.request, {
  337. 'title': 'Информация о партнере',
  338. 'object': self.object,
  339. }))
  340. return context
  341. def get_success_url(self):
  342. return reverse('test-page')