views.py 6.4 KB

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