views_old.py 14 KB

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