Merge branch 'Andr' into develop
This commit is contained in:
commit
22b045894c
6 files changed
+180
-72
No files matched your search
+20
-14
@@ -1,5 +1,6 @@
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.response import Response
|
||||
from django.db.models import Count
|
||||
from django.db.models import Q
|
||||
from .models import *
|
||||
from userauth.models import *
|
||||
@@ -12,7 +13,7 @@ class GetForThn(APIView):
|
||||
def get(self, request):
|
||||
user_login = request.GET.get('login')
|
||||
all_emps = DictEmployee.objects.exclude(
|
||||
login=user_login).exclude(post='Начальник инспекции')
|
||||
login=user_login).exclude(post='Начальник инспекции').exclude(deleted=1)
|
||||
return Response(GetEmpSerializer(all_emps, many=True).data)
|
||||
|
||||
|
||||
@@ -21,32 +22,36 @@ class GetForBst(APIView):
|
||||
user_login = request.GET.get('login')
|
||||
dep_id = request.GET.get('dep')
|
||||
emp_user = DictEmployee.objects.filter(Q(id_dict_department=dep_id), ~Q(
|
||||
post="Начальник отдела"), ~Q(login=user_login))
|
||||
post="Начальник отдела"), ~Q(login=user_login)).exclude(deleted=1)
|
||||
return Response(GetEmpSerializer(emp_user, many=True).data)
|
||||
|
||||
|
||||
class SetThanks(APIView):
|
||||
def post(self, request):
|
||||
cand_thanks_id = request.GET.get('id')
|
||||
ThanksVote.objects.update_or_create(
|
||||
cand_name_id=cand_thanks_id,
|
||||
defaults=None
|
||||
voted_user = request.data['voted_user']
|
||||
cand_name = request.data['cand_name_id']
|
||||
ThanksVote.objects.create(
|
||||
voted_user=voted_user,
|
||||
cand_name=cand_name
|
||||
)
|
||||
return Response("Ваш голос добавлен!")
|
||||
|
||||
|
||||
class GetThanks(APIView):
|
||||
def get(self, request):
|
||||
all_thanks = ThanksVote.objects.all()
|
||||
return Response(ThanksVoteSerializer(all_thanks, many=True).data)
|
||||
# Группировка товаров по имени и подсчет каждого
|
||||
count_thanks = ThanksVote.objects.values(
|
||||
'cand_name').annotate(total=Count('id'))
|
||||
return Response(count_thanks)
|
||||
|
||||
|
||||
class SetBest(APIView):
|
||||
def post(self, request):
|
||||
cand_best_id = request.GET.get('id')
|
||||
BestVote.objects.update_or_create(
|
||||
cand_name_id=cand_best_id,
|
||||
defaults=None
|
||||
voted_user = request.data['voted_user']
|
||||
cand_name = request.data['cand_name_id']
|
||||
BestVote.objects.create(
|
||||
voted_user=voted_user,
|
||||
cand_name=cand_name
|
||||
)
|
||||
return Response("Ваш голос добавлен!")
|
||||
|
||||
@@ -54,5 +59,6 @@ class SetBest(APIView):
|
||||
|
||||
class GetBest(APIView):
|
||||
def get(self, request):
|
||||
all_thanks = BestVote.objects.all()
|
||||
return Response(BestVoteSerializer(all_thanks, many=True).data)
|
||||
count_bests = ThanksVote.objects.values(
|
||||
'cand_name').annotate(total=Count('id'))
|
||||
return Response(count_bests)
|
||||
Reference in new issue
Block a user