AlexP077 3 years ago committed by Dmitry Titov
parent 3423da67c2
commit 3ce6e89413

@ -101,3 +101,6 @@ services:
- db
- django
restart: always
volumes:
rabbitmq_data:
rabbitmq_log:

@ -3,13 +3,15 @@ import os
from celery import Celery
from postamates.settings import CELERY_BROKER_URL
from postamates.settings import CELERY_NAMESPACE
from postamates.settings import PROJECT_NAME
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'postamates.settings')
app = Celery(
PROJECT_NAME, broker=CELERY_BROKER_URL,
include=['service.tasks'], )
app = Celery('postamates', broker=CELERY_BROKER_URL,
include=["service.tasks"], )
app.config_from_object('django.conf:settings', namespace='CELERY')
app.config_from_object('django.conf:settings', namespace=CELERY_NAMESPACE)
app.autodiscover_tasks()

@ -9,7 +9,6 @@ https://docs.djangoproject.com/en/3.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.2/ref/settings/
"""
import os
from pathlib import Path
@ -166,4 +165,7 @@ REST_REGISTRATION = {
SRID = 4326
# celery
CELERY_BROKER_URL = "amqp://loyalty-rabbit"
CELERY_BROKER_URL = 'amqp://loyalty-rabbit'
CELERY_NAMESPACE = 'CELERY'
PROJECT_NAME = 'postamates'
CACHE_TIMEOUT = 0

@ -7,6 +7,7 @@ from drf_yasg.views import get_schema_view
from rest_framework import permissions
from rest_framework import routers
from postamates.settings import CACHE_TIMEOUT
from service import views
router = routers.DefaultRouter()
@ -35,8 +36,7 @@ urlpatterns = [
url(r'upload_dist/', views.upload_dist, name='upload_dist'),
url(r'me/', views.get_current_user, name='me'),
re_path(r'^swagger(?P<format>\.json|\.yaml)$', schema_view.without_ui(cache_timeout=0), name='schema-json'),
re_path(r'^swagger/$', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
# re_path(r'^redoc/$', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
re_path(r'^swagger/$', schema_view.with_ui('swagger', cache_timeout=CACHE_TIMEOUT), name='schema-swagger-ui'),
]
USE_X_FORWARDED_HOST = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

@ -40,7 +40,6 @@ def load_ao_and_rayons(
okr = obj['properties']['okrug']
ao = models.AO.objects.get(name=okr)
models.Rayon.objects.create(**{'name': name, 'polygon': GEOSGeometry(str(MultiPolygon(coords))), 'AO': ao})
print('AO and Rayons loaded')
def load_rivals(filepath: str):

@ -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'])

Loading…
Cancel
Save