views.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. from django.urls import reverse_lazy
  2. import requests
  3. from webservice_running.models import OrdersLocal
  4. from django.http import HttpResponse
  5. from webservice_running.apps import api
  6. from core.settings import API_URL
  7. from webservice_running.forms import OrderRegForm, RegisterUserForm
  8. from django.shortcuts import redirect, render
  9. from django.contrib.auth.mixins import UserPassesTestMixin
  10. from django_tables2 import SingleTableView
  11. from django.urls import reverse
  12. from django.views.generic.edit import UpdateView, CreateView, DeleteView
  13. from webservice_running.tables import OrderList
  14. class OrderReg(CreateView):
  15. model = OrdersLocal
  16. form_class = OrderRegForm
  17. template_name = "webservice_running/order_reg.html"
  18. def get_context_data(self, **kwargs):
  19. context = super().get_context_data(**kwargs)
  20. context.update({
  21. 'title': ('Заявка на экскурсию'),
  22. 'object': self.object,
  23. "current_page": "order_reg"
  24. })
  25. return context
  26. #def testing(self, queryset, is_descending):
  27. # queryset = queryset.annotate.order_by("-" if is_descending else "")
  28. # return (queryset, True)
  29. def get_success_url(self):
  30. return reverse('webservice_running:order_reg')
  31. def test_func(self) -> bool or None:
  32. group_names = ('METASERVICE-ADMIN')
  33. if bool(self.request.user.groups.filter(name=group_names)) or self.request.user:
  34. return True
  35. return False
  36. class OrderRegUpdateView(UserPassesTestMixin, UpdateView):
  37. model = OrdersLocal
  38. form_class = OrderRegForm
  39. template_name = "SharixAdmin/order_reg.html"
  40. def get_context_data(self, **kwargs):
  41. context = super().get_context_data(**kwargs)
  42. context.update({
  43. 'title': _('Заявка на экскурсию'),
  44. 'object': self.object,
  45. "current_page": "order_reg"
  46. })
  47. return context
  48. def test_func(self) -> bool or None:
  49. group_names = ('METASERVICE-ADMIN')
  50. if bool(self.request.user.groups.filter(name=group_names)) or self.request.user:
  51. return True
  52. return False
  53. def get_success_url(self):
  54. return reverse('order_reg')
  55. class OrderRegDelete(UserPassesTestMixin, DeleteView):
  56. model = OrdersLocal
  57. template_name = "SharixAdmin/order_reg_delete.html"
  58. def get_context_data(self, **kwargs):
  59. context = super().get_context_data(**kwargs)
  60. context.update({
  61. 'title': 'Заявка на экскурсию',
  62. 'object': self.object,
  63. "current_page": "order_reg"
  64. })
  65. return context
  66. def get_success_url(self):
  67. return reverse('order_reg')
  68. def test_func(self) -> bool or None:
  69. group_names = ('METASERVICE-ADMIN')
  70. if bool(self.request.user.groups.filter(name=group_names)) or self.request.user.is_superuser:
  71. return True
  72. return False
  73. class OrdersListView(UserPassesTestMixin, SingleTableView):
  74. table_class = OrderList
  75. queryset = OrdersLocal.objects.all()
  76. template_name = 'webservice_running/order_list.html'
  77. def get_context_data(self, **kwargs):
  78. context = super().get_context_data(**kwargs)
  79. context.update({
  80. 'title': 'Мои заказы',
  81. 'object_list': context['object_list'],
  82. "current_page": "order_list"
  83. })
  84. return context
  85. def test_func(self) -> bool or None:
  86. group_names = ('PROVIDER')
  87. if bool(self.request.user.groups.filter(name=group_names)) or self.request.user:
  88. return True
  89. return False
  90. def registration(request):
  91. if request.method == 'POST':
  92. form = RegisterUserForm(request.POST)
  93. if form.is_valid():
  94. form.save()
  95. return redirect('authweb')
  96. else:
  97. form = RegisterUserForm()
  98. return render(request, 'webservice_running/registration.html', {'form': form})