views.py 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. {'title':'Информация о сервисе', 'link':'partner_information/add/', 'sel':'hdd-network'},
  94. ]
  95. def get_context(request, page_context) -> dict:
  96. base_context = {
  97. "title":page_context['title'],
  98. 'url_path':resolve(request.path_info).url_name,
  99. 'menu':menu
  100. }
  101. context = dict(list(base_context.items()) + list(page_context.items()))
  102. return context
  103. class ServiceTypeUpdateView(UpdateView):
  104. model = ServiceType
  105. form_class = ServiceTypeUpdateForm
  106. template_name = "SharixAdmin/service_type_form.html"
  107. def get_context_data(self, **kwargs):
  108. context = super().get_context_data(**kwargs)
  109. context.update(get_context(self.request, {
  110. 'title': 'Услуги сервиса',
  111. 'object': self.object,
  112. }))
  113. return context
  114. def get_success_url(self):
  115. return reverse('service_type')
  116. class ServiceTypeCreate(CreateView):
  117. model = ServiceType
  118. form_class = ServiceTypeCreateForm
  119. template_name = "SharixAdmin/service_type_form.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': self.object,
  125. }))
  126. return context
  127. def get_success_url(self):
  128. return reverse('service_type')
  129. class ServiceTypeDelete(DeleteView):
  130. model = ServiceType
  131. template_name = "SharixAdmin/service_type_delete.html"
  132. def get_context_data(self, **kwargs):
  133. context = super().get_context_data(**kwargs)
  134. context.update(get_context(self.request, {
  135. 'title': 'Услуги сервиса',
  136. 'object': self.object,
  137. }))
  138. return context
  139. def get_success_url(self):
  140. return reverse('service_type')
  141. class ServiceTypeListView(SingleTableView):
  142. table_class = ServiceTypeTable
  143. queryset = ServiceType.objects.all()
  144. template_name = 'SharixAdmin/service_type.html'
  145. # paginate_by = 2
  146. def get_context_data(self, **kwargs):
  147. context = super().get_context_data(**kwargs)
  148. context.update(get_context(self.request, {
  149. 'title': 'Услуги сервиса',
  150. 'object_list': context['object_list'],
  151. }))
  152. return context
  153. class ServiceInformationUpdateView(UpdateView):
  154. model = Service
  155. form_class = ServiceInformationUpdateForm
  156. template_name = "SharixAdmin/service_information_form.html"
  157. def get_context_data(self, **kwargs):
  158. context = super().get_context_data(**kwargs)
  159. context.update(get_context(self.request, {
  160. 'title': 'Информация о сервисе',
  161. 'object': self.object,
  162. }))
  163. return context
  164. def get_success_url(self):
  165. return reverse('test-page')
  166. class ServiceInformationCreate(CreateView):
  167. model = Service
  168. form_class = ServiceInformationCreateForm
  169. template_name = "SharixAdmin/service_information_form.html"
  170. def get_context_data(self, **kwargs):
  171. context = super().get_context_data(**kwargs)
  172. context.update(get_context(self.request, {
  173. 'title': 'Информация о сервисе',
  174. 'object': self.object,
  175. }))
  176. return context
  177. def get_success_url(self):
  178. return reverse('test-page')
  179. #Shema views
  180. @login_required
  181. def schema_v3(request):
  182. return render(request, "SharixAdmin/schema.html")