1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- from django.urls import reverse_lazy, reverse
- import requests
- from django.http import HttpResponse
- from webservice_running.apps import api
- from core.settings import API_URL
- from webservice_running.forms import OrderRegForm, RegisterUserForm, OrderLocalForm
- from webservice_running.models import OrdersLocal
- from django.shortcuts import redirect, render
- from django.views.generic.edit import CreateView
- from django.utils.translation import gettext as _
- #from django.contrib.auth.mixins import UserPassesTestMixin
- def order_reg(request):
- if request.method == 'POST':
- form = OrderRegForm(request.POST)
- if form.is_valid():
- data = request.POST
- responce = requests.post(f'{API_URL}/webservice/api/webservice/', data = data, headers=api.headers)
- return HttpResponse(responce.text)
- else:
- form = OrderRegForm()
- return render(request, 'webservice_running/order_reg.html', {'form': form})
- 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})
- #class order_new(UserPassesTestMixin, CreateView):
- class order_new(CreateView):
- model = OrdersLocal
- form_class = OrderLocalForm
- template_name = "webservice_running/order_local.html"
- def get_context_data(self, **kwargs):
- page_context = super().get_context_data(**kwargs)
- base_context = {
- 'title': _('Форма создания заказа'),
- 'object': self.object,
- 'current_page': 'order_new'
- }
- context = dict(list(base_context.items()) + list(page_context.items()))
- 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_new')
- 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
|