123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- 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})
|