1
0

views.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 OrdersListView(UserPassesTestMixin, SingleTableView):
  37. table_class = OrderList
  38. queryset = OrdersLocal.objects.all()
  39. template_name = 'webservice_running/order_list.html'
  40. def get_context_data(self, **kwargs):
  41. context = super().get_context_data(**kwargs)
  42. context.update({
  43. 'title': 'Мои заказы',
  44. 'object_list': context['object_list'],
  45. "current_page": "order_list"
  46. })
  47. return context
  48. def test_func(self) -> bool or None:
  49. group_names = ('PROVIDER')
  50. if bool(self.request.user.groups.filter(name=group_names)) or self.request.user:
  51. return True
  52. return False
  53. def registration(request):
  54. if request.method == 'POST':
  55. form = RegisterUserForm(request.POST)
  56. if form.is_valid():
  57. form.save()
  58. return redirect('authweb')
  59. else:
  60. form = RegisterUserForm()
  61. return render(request, 'webservice_running/registration.html', {'form': form})