views.py 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. import json
  2. from django.shortcuts import render
  3. from django.http import HttpResponseRedirect, HttpResponse, JsonResponse
  4. from django.contrib.auth.views import LoginView
  5. from django.urls import reverse_lazy, resolve, reverse
  6. from django.contrib.auth.decorators import login_required
  7. from django_tables2 import SingleTableView
  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 .tables import *
  13. from django import template
  14. from django.views.generic.edit import UpdateView, CreateView
  15. from metaservicesynced.models import *
  16. # Create your views here.
  17. @login_required
  18. def index(request):
  19. ph_num = str(request.user.phone_number)
  20. convert_ph_num = f"+{ph_num[:1]} ({ph_num[1:4]}) {ph_num[4:7]}-{ph_num[7:9]}-{ph_num[9:11]}"
  21. #print(convert_ph_num)
  22. context = get_context(request, {
  23. 'title':'Главная/баланс',
  24. 'phone':convert_ph_num
  25. })
  26. return render(request, 'SharixAdmin/main.html', context)
  27. @login_required
  28. def transactions(request):
  29. context = get_context(request, {
  30. 'title':'История платежей',
  31. })
  32. return render(request, 'SharixAdmin/transactions.html', context)
  33. @login_required
  34. def trans_id(request, trans_id):
  35. context = get_context(request, {
  36. 'title':'Услуга'
  37. })
  38. return render(request, 'SharixAdmin/trans_carried.html', context)
  39. @login_required
  40. def balance(request):
  41. context = get_context(request, {
  42. 'title':'Пополнить баланс'
  43. })
  44. if request.method == 'POST':
  45. if float(request.POST['price']) > 0:
  46. context = get_context(request, {
  47. 'title':'Пополнить баланс',
  48. 'msg':'Оплата прошла успешно ;)'
  49. })
  50. return render(request, "SharixAdmin/balance_success.html", context)
  51. else:
  52. context = get_context(request, {
  53. 'title':'Пополнить баланс',
  54. 'msg':'Оплата не прошла ;('
  55. })
  56. return render(request, "SharixAdmin/balance_success.html", context)
  57. return render(request, "SharixAdmin/balance.html", context)
  58. def logout_view(request):
  59. logout(request)
  60. return HttpResponseRedirect(reverse('authweb'))
  61. class LoginSharix(LoginView):
  62. form_class = LoginUserForm
  63. template_name = 'SharixAdmin/auth.html'
  64. def get_success_url(self):
  65. print(self.request.GET['next'])
  66. return reverse_lazy('home')
  67. def testPage(request):
  68. context = get_context(request, {
  69. 'title':'Страница в разработке'
  70. })
  71. return render(request, "SharixAdmin/test.html", context)
  72. menu = [
  73. {'title':'Главная/баланс', 'link':'home', 'sel':'house'},
  74. {'title':'Платежная информация', 'link':'test-page', 'sel':'credit-card'},
  75. {'title':'История платежей', 'link':'trans','sel':'clock-history'},
  76. {'title':'Курсы', 'link':'course', 'sel':'education'},
  77. {'title':'Личная информация', 'link':'test-page', 'sel':'person'},
  78. {'title':'Управление сервисами', 'link':'test-page', 'sel':'hdd-network'},
  79. {'title':'Мои связи', 'link':'test-page', 'sel':'people'},
  80. {'title':'Сотрудничество', 'link':'test-page', 'sel':'sotrud'},
  81. {'title':'Техподдержка', 'link':'test-page', 'sel':'gear'},
  82. {'title':'Мои заявки', 'link':'tickets', 'sel':'tikets'},
  83. {'title':'Исполнители', 'link':'provider', 'sel':'people'},
  84. {'title':'Тарифы услуг', 'link':'service_tariff', 'sel':'person'},
  85. ]
  86. def get_context(request, page_context) -> dict:
  87. base_context = {
  88. "title":page_context['title'],
  89. 'url_path':resolve(request.path_info).url_name,
  90. 'menu':menu
  91. }
  92. context = dict(list(base_context.items()) + list(page_context.items()))
  93. return context
  94. @login_required
  95. def change_provider_status(request):
  96. if request.method == 'POST':
  97. provider_id = request.POST.get('provider_id')
  98. new_status = request.POST.get('new_status')
  99. provider = Provider.objects.get(pk=provider_id)
  100. provider.status = new_status
  101. provider.save()
  102. return JsonResponse({'status': 'success'})
  103. else:
  104. return JsonResponse({'status': 'error'})
  105. class ServiceTariffUpdateView(UpdateView):
  106. model = Service
  107. form_class = ServiceTariffUpdateForm
  108. template_name = "SharixAdmin/service_tariff_form.html"
  109. def get_context_data(self, **kwargs):
  110. context = super().get_context_data(**kwargs)
  111. context.update(get_context(self.request, {
  112. 'title': 'Тарифы услуг',
  113. 'object': self.object,
  114. }))
  115. return context
  116. def get_success_url(self):
  117. return reverse('service_tariff')
  118. class ServiceTariffCreate(CreateView):
  119. model = Service
  120. form_class = ServiceTariffCreateForm
  121. template_name = "SharixAdmin/service_tariff_form.html"
  122. def get_context_data(self, **kwargs):
  123. context = super().get_context_data(**kwargs)
  124. context.update(get_context(self.request, {
  125. 'title': 'Тарифы услуг',
  126. 'object': self.object,
  127. }))
  128. return context
  129. def get_success_url(self):
  130. return reverse('service_tariff')
  131. class ProviderListView(SingleTableView):
  132. table_class = ProviderTable
  133. queryset = Provider.objects.all()
  134. template_name = 'SharixAdmin/provider.html'
  135. def get_context_data(self, **kwargs):
  136. context = super().get_context_data(**kwargs)
  137. context.update(get_context(self.request, {
  138. 'title': 'Исполнители',
  139. 'object_list': context['object_list'],
  140. }))
  141. return context
  142. class ServiceTariffListView(SingleTableView):
  143. table_class = ServiceTariffTable
  144. queryset = Service.objects.all()
  145. template_name = 'SharixAdmin/service_tariff.html'
  146. # paginate_by = 2
  147. def get_context_data(self, **kwargs):
  148. context = super().get_context_data(**kwargs)
  149. context.update(get_context(self.request, {
  150. 'title': 'Тарифы услуг',
  151. 'object_list': context['object_list'],
  152. }))
  153. return context
  154. #Shema views
  155. @login_required
  156. def schema_v3(request):
  157. return render(request, "SharixAdmin/schema.html")