from django.http import Http404, HttpResponse from openlocal.serializer import OrdersLocalSerializer from rest_framework import viewsets, permissions, status from rest_framework.response import Response from rest_framework.exceptions import NotFound from openlocal.models import OrdersLocal from metaservicesynced.models import Orders, Service, ServiceType, Provider, Client from SharixAdmin.models import SharixUser from tickets.models import Task class OrdersLocalMVS(viewsets.ModelViewSet): queryset = OrdersLocal.objects.all() serializer_class = OrdersLocalSerializer #permission_classes = [IsOwnerOrReadOnly] permission_classes = [permissions.IsAuthenticated] def update(self, request, *args, **kwargs): if request.data['order_synced']: order = Orders.objects.get(pk=int(request.data['order_synced'])) try: #Подумать над этим if request.data['is_global'] == True: order.is_global = True elif request.data['is_gloabl'] == False: order.is_global = False if request.data['is_visible'] == True: order.is_visible = True elif request.data['is_visible'] == False: order.is_visible = False order.service = Service.objects.get(pk=request.data['service']) order.service_type = ServiceType.objects.get(pk=request.data['service_type']) order.provider = Provider.objects.get(pk=request.data['provider']) order.receiver = SharixUser.objects.get(pk=request.data['receiver']) order.client_id = Client.objects.get(pk=request.data['client_id']) except Exception as ex: print(ex) #raise NotFound(str(ex)) order.id_metaservice = request.data['id_metaservice'] or order.id_metaservice order.state = request.data['state'] or order.state order.time_placed = request.data['time_placed'] or order.time_placed order.time_start = request.data['time_start'] or order.time_start order.time_start_real = request.data['time_start_real'] or order.time_start_real order.time_start_predicted = request.data['time_start_predicted'] or order.time_start_predicted order.time_finish_predicted = request.data['time_finish_predicted'] or order.time_finish_predicted order.time_finish_real = request.data['time_finish_real'] or order.time_finish_real order.predicted_price = request.data['predicted_price'] or order.predicted_price order.real_price = request.data['real_price'] or order.real_price order.save() if request.data['ticket']: ticket = Task.objects.get(pk=request.data['ticket']) ticket.status = request.data['status'] or ticket.status ticket.priority = request.data['priority'] or ticket.priority ticket.title = request.data['title'] or ticket.title ticket.note = request.data['note'] or ticket.note ticket.due_date = request.data['due_date'] or ticket.due_date ticket.status_changed_date = request.data['status_changed_date'] or ticket.status_changed_date ticket.save() return super().update(request, *args, **kwargs)