from django.urls import reverse_lazy import requests from webservice_running.models import OrdersLocal from django.http import HttpResponse from webservice_running.apps import api from core.settings import API_URL from webservice_running.forms import OrderRegForm, RegisterUserForm from django.shortcuts import redirect, render from django.contrib.auth.mixins import UserPassesTestMixin from django_tables2 import SingleTableView from django.urls import reverse from django.views.generic.edit import UpdateView, CreateView, DeleteView from webservice_running.tables import OrderList class OrderReg(CreateView): model = OrdersLocal form_class = OrderRegForm template_name = "webservice_running/order_reg.html" def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context.update({ 'title': ('Заявка на экскурсию'), 'object': self.object, "current_page": "order_reg" }) return context #def testing(self, queryset, is_descending): # queryset = queryset.annotate.order_by("-" if is_descending else "") # return (queryset, True) def get_success_url(self): return reverse('webservice_running:order_reg') def test_func(self) -> bool or None: group_names = ('METASERVICE-ADMIN') if bool(self.request.user.groups.filter(name=group_names)) or self.request.user: return True return False class OrderRegUpdateView(UserPassesTestMixin, UpdateView): model = OrdersLocal form_class = OrderRegForm template_name = "SharixAdmin/order_reg.html" def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context.update({ 'title': _('Заявка на экскурсию'), 'object': self.object, "current_page": "order_reg" }) return context def test_func(self) -> bool or None: group_names = ('METASERVICE-ADMIN') if bool(self.request.user.groups.filter(name=group_names)) or self.request.user: return True return False def get_success_url(self): return reverse('order_reg') class OrderRegDelete(UserPassesTestMixin, DeleteView): model = OrdersLocal template_name = "SharixAdmin/order_reg_delete.html" def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context.update({ 'title': 'Заявка на экскурсию', 'object': self.object, "current_page": "order_reg" }) return context def get_success_url(self): return reverse('order_reg') def test_func(self) -> bool or None: group_names = ('METASERVICE-ADMIN') if bool(self.request.user.groups.filter(name=group_names)) or self.request.user.is_superuser: return True return False class OrdersListView(UserPassesTestMixin, SingleTableView): table_class = OrderList queryset = OrdersLocal.objects.all() template_name = 'webservice_running/order_list.html' def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context.update({ 'title': 'Мои заказы', 'object_list': context['object_list'], "current_page": "order_list" }) return context def test_func(self) -> bool or None: group_names = ('PROVIDER') if bool(self.request.user.groups.filter(name=group_names)) or self.request.user: return True return False def registration(request): if request.method == 'POST': form = RegisterUserForm(request.POST) if form.is_valid(): form.save() return redirect('authweb') else: form = RegisterUserForm() return render(request, 'webservice_running/registration.html', {'form': form})