|
|
|
|
@ -28,20 +28,21 @@ from django.shortcuts import redirect
|
|
|
|
|
from django.contrib import messages
|
|
|
|
|
from django_filters.rest_framework import DjangoFilterBackend
|
|
|
|
|
from rest_framework import filters
|
|
|
|
|
from service.utils import CustomReadOnlyModelViewSet
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AOViewSet(ReadOnlyModelViewSet):
|
|
|
|
|
class AOViewSet(CustomReadOnlyModelViewSet):
|
|
|
|
|
serializer_class = serializers.AOSerializer
|
|
|
|
|
queryset = models.AO.objects
|
|
|
|
|
permission_classes = [AllowAny]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PostAndPVZCategoryViewSet(ReadOnlyModelViewSet):
|
|
|
|
|
class PostAndPVZCategoryViewSet(CustomReadOnlyModelViewSet):
|
|
|
|
|
serializer_class = serializers.PostAndPVZCategorySerializer
|
|
|
|
|
queryset = models.Post_and_pvzCategory.objects
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class OtherObjectsCategoryViewSet(ReadOnlyModelViewSet):
|
|
|
|
|
class OtherObjectsCategoryViewSet(CustomReadOnlyModelViewSet):
|
|
|
|
|
serializer_class = serializers.OtherObjectsCategorySerializer
|
|
|
|
|
queryset = models.OtherObjectsCategory.objects
|
|
|
|
|
|
|
|
|
|
@ -194,27 +195,31 @@ class PlacementPointViewSet(ReadOnlyModelViewSet):
|
|
|
|
|
|
|
|
|
|
@action(detail=False, methods=['get'])
|
|
|
|
|
def filters(self, request):
|
|
|
|
|
qs = self.get_queryset()
|
|
|
|
|
keys = (
|
|
|
|
|
'age_day', 'prediction_first', 'prediction_current',
|
|
|
|
|
'plan_first', 'plan_current', 'fact', 'delta_first',
|
|
|
|
|
'delta_current', 'flat_cnt', 'year_bld', 'levels',
|
|
|
|
|
'doors', 'flats_cnt', 'popul_home', 'popul_job',
|
|
|
|
|
'other_post_cnt', 'target_post_cnt', 'yndxfood_cnt',
|
|
|
|
|
'yndxfood_sum', 'yndxfood_cnt_cst',
|
|
|
|
|
)
|
|
|
|
|
temp_data = {
|
|
|
|
|
key: [
|
|
|
|
|
x for x in list(set(qs.values_list(key, flat=True))) if
|
|
|
|
|
x is not None
|
|
|
|
|
]
|
|
|
|
|
for key in keys
|
|
|
|
|
}
|
|
|
|
|
data = {
|
|
|
|
|
key: [
|
|
|
|
|
min(temp_data[key]), max(temp_data[key]),
|
|
|
|
|
] if temp_data[key] else [0, 100] for key in keys
|
|
|
|
|
}
|
|
|
|
|
def get_filter_data():
|
|
|
|
|
qs = self.get_queryset()
|
|
|
|
|
keys = (
|
|
|
|
|
'age_day', 'prediction_first', 'prediction_current',
|
|
|
|
|
'plan_first', 'plan_current', 'fact', 'delta_first',
|
|
|
|
|
'delta_current', 'flat_cnt', 'year_bld', 'levels',
|
|
|
|
|
'doors', 'flats_cnt', 'popul_home', 'popul_job',
|
|
|
|
|
'other_post_cnt', 'target_post_cnt', 'yndxfood_cnt',
|
|
|
|
|
'yndxfood_sum', 'yndxfood_cnt_cst',
|
|
|
|
|
)
|
|
|
|
|
temp_data = {
|
|
|
|
|
key: [
|
|
|
|
|
x for x in list(set(qs.values_list(key, flat=True))) if
|
|
|
|
|
x is not None
|
|
|
|
|
]
|
|
|
|
|
for key in keys
|
|
|
|
|
}
|
|
|
|
|
data = {
|
|
|
|
|
key: [
|
|
|
|
|
min(temp_data[key]), max(temp_data[key]),
|
|
|
|
|
] if temp_data[key] else [0, 100] for key in keys
|
|
|
|
|
}
|
|
|
|
|
return data
|
|
|
|
|
data = utils.cached_func('get_filter_data', get_filter_data, 120)
|
|
|
|
|
|
|
|
|
|
return Response(data, status=HTTPStatus.OK)
|
|
|
|
|
|
|
|
|
|
@action(detail=False, methods=['get'])
|
|
|
|
|
|