|
|
|
|
@ -1,10 +1,9 @@
|
|
|
|
|
import warnings
|
|
|
|
|
from http import HTTPStatus
|
|
|
|
|
|
|
|
|
|
from django.db.models import Q
|
|
|
|
|
from django.http import HttpResponse
|
|
|
|
|
from django.http import JsonResponse
|
|
|
|
|
from rest_framework import status
|
|
|
|
|
from rest_framework import status as http_status
|
|
|
|
|
from rest_framework.decorators import action
|
|
|
|
|
from rest_framework.decorators import api_view
|
|
|
|
|
from rest_framework.decorators import permission_classes
|
|
|
|
|
@ -17,9 +16,9 @@ from service import models
|
|
|
|
|
from service import pagination
|
|
|
|
|
from service import serializers
|
|
|
|
|
from service import utils
|
|
|
|
|
from service.tasks import raschet
|
|
|
|
|
from service.permissions import UserPermission
|
|
|
|
|
from service.service import PointService
|
|
|
|
|
from service.tasks import raschet
|
|
|
|
|
from service.utils import load_data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -119,7 +118,7 @@ class PlacementPointViewSet(ReadOnlyModelViewSet):
|
|
|
|
|
min(temp_data[key]), max(temp_data[key]),
|
|
|
|
|
] if temp_data[key] else [0, 100] for key in keys
|
|
|
|
|
}
|
|
|
|
|
return Response(data, status=status.HTTP_200_OK)
|
|
|
|
|
return Response(data, status=HTTPStatus.OK)
|
|
|
|
|
|
|
|
|
|
@action(detail=False, methods=['get'])
|
|
|
|
|
def search_address(self, request):
|
|
|
|
|
@ -140,11 +139,11 @@ class PlacementPointViewSet(ReadOnlyModelViewSet):
|
|
|
|
|
qs = self.get_queryset()
|
|
|
|
|
new_status = self.request.GET.get('status')
|
|
|
|
|
if not new_status:
|
|
|
|
|
return Response({'message': 'No status'}, 400)
|
|
|
|
|
return Response({'message': 'No status'}, HTTPStatus.BAD_REQUEST)
|
|
|
|
|
PointService.update_status(qs, new_status)
|
|
|
|
|
return Response(
|
|
|
|
|
{'message': 'status updated'},
|
|
|
|
|
status=http_status.HTTP_200_OK,
|
|
|
|
|
status=HTTPStatus.OK,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@action(detail=False, methods=['put'])
|
|
|
|
|
@ -152,24 +151,24 @@ class PlacementPointViewSet(ReadOnlyModelViewSet):
|
|
|
|
|
point_id = request.GET.get('postamat_id')
|
|
|
|
|
fact = request.GET.get('fact')
|
|
|
|
|
if not point_id or not fact or not fact.isdigit():
|
|
|
|
|
return Response(status=http_status.HTTP_400_BAD_REQUEST)
|
|
|
|
|
return Response(status=HTTPStatus.BAD_REQUEST)
|
|
|
|
|
qs = models.PlacementPoint.objects.filter(postamat_id=point_id)
|
|
|
|
|
if not qs:
|
|
|
|
|
return Response(status=http_status.HTTP_404_NOT_FOUND)
|
|
|
|
|
return Response(status=HTTPStatus.NOT_FOUND)
|
|
|
|
|
qs.update(**{'fact': fact})
|
|
|
|
|
return Response({'message': 'fact updated'}, status=http_status.HTTP_200_OK)
|
|
|
|
|
return Response({'message': 'fact updated'}, status=HTTPStatus.OK)
|
|
|
|
|
|
|
|
|
|
@action(detail=False, methods=['put'])
|
|
|
|
|
def update_postamat_id(self, request):
|
|
|
|
|
postamat_id = request.GET.get('postamat_id')
|
|
|
|
|
point_id = request.GET.get('id')
|
|
|
|
|
if not point_id or not postamat_id:
|
|
|
|
|
return Response(status=http_status.HTTP_400_BAD_REQUEST)
|
|
|
|
|
return Response(status=HTTPStatus.BAD_REQUEST)
|
|
|
|
|
qs = PointService.get_point_by_id(point_id)
|
|
|
|
|
if not qs:
|
|
|
|
|
return Response(status=http_status.HTTP_404_NOT_FOUND)
|
|
|
|
|
return Response(status=HTTPStatus.NOT_FOUND)
|
|
|
|
|
PointService().update_postamat_id(point_id, postamat_id)
|
|
|
|
|
return Response({'message': 'Postamat id updated'}, status=http_status.HTTP_200_OK)
|
|
|
|
|
return Response({'message': 'Postamat id updated'}, status=HTTPStatus.OK)
|
|
|
|
|
|
|
|
|
|
@action(detail=False, methods=['get'])
|
|
|
|
|
def to_excel(self, request):
|
|
|
|
|
@ -185,12 +184,12 @@ class PlacementPointViewSet(ReadOnlyModelViewSet):
|
|
|
|
|
@action(detail=False, methods=['get'])
|
|
|
|
|
def get_10k(self, request):
|
|
|
|
|
pred = PointService.get_first_10_k()
|
|
|
|
|
return Response({'prediction_current': pred}, status=http_status.HTTP_200_OK)
|
|
|
|
|
return Response({'prediction_current': pred}, status=HTTPStatus.OK)
|
|
|
|
|
|
|
|
|
|
@action(detail=False, methods=['get'])
|
|
|
|
|
def start(self, request):
|
|
|
|
|
raschet.delay(5)
|
|
|
|
|
return Response('Sucess', 200)
|
|
|
|
|
return Response('Sucess', status=HTTPStatus.OK)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class refresh_placement_points(APIView):
|
|
|
|
|
@ -199,7 +198,7 @@ class refresh_placement_points(APIView):
|
|
|
|
|
warnings.filterwarnings('ignore')
|
|
|
|
|
file = request.FILES['file']
|
|
|
|
|
load_data(file)
|
|
|
|
|
return Response(status=http_status.HTTP_200_OK)
|
|
|
|
|
return Response(status=HTTPStatus.OK)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class load_ao_and_rayons(APIView):
|
|
|
|
|
@ -209,7 +208,7 @@ class load_ao_and_rayons(APIView):
|
|
|
|
|
file_ao = request.FILES['file_ao']
|
|
|
|
|
file_rayon = request.FILES['file_rayon']
|
|
|
|
|
utils.load_ao_and_rayons(file_ao, file_rayon)
|
|
|
|
|
return Response(status=http_status.HTTP_200_OK)
|
|
|
|
|
return Response(status=HTTPStatus.OK)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@api_view(['POST'])
|
|
|
|
|
|