P-106
This commit is contained in:
1 parent
cabdbf9ccf
commit
e26460f05b
1 file changed
+13
-7
+13
-7
@@ -133,17 +133,22 @@ class GetResults(APIView):
|
|||||||
|
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
vote_id = request.data.get('id')
|
vote_id = request.data.get('id')
|
||||||
vote = Vote.objects.get(id=vote_id)
|
try:
|
||||||
|
vote = Vote.objects.get(id=vote_id)
|
||||||
|
except Exception as e:
|
||||||
|
return Response({'status': 'error', 'message': str(e)}, status=400)
|
||||||
|
|
||||||
answers_employee = Answer.objects.filter(question__vote=vote).filter(question__settings__choice="employee").values_list('answer', flat=True)
|
answers_employee = Answer.objects.filter(question__vote=vote).filter(question__settings__choice="employee").values_list('answer', flat=True)
|
||||||
results = Result.objects.filter(answer__question__vote=vote).annotate(count=Count('id')).values('answer__answer').annotate(count=Count('id'))
|
results = Result.objects.filter(answer__question__vote=vote).annotate(count=Count('id')).values('answer__answer').annotate(count=Count('id'))
|
||||||
employees = DictEmployee.objects.filter(id__in=answers_employee)
|
|
||||||
employee_dict = {employee.id: employee for employee in employees}
|
|
||||||
|
|
||||||
for result in results:
|
if answers_employee:
|
||||||
if result['answer__answer'] in answers_employee:
|
employees = DictEmployee.objects.filter(id__in=answers_employee)
|
||||||
employee_data = employee_dict.get(int(result['answer__answer']))
|
employee_dict = {employee.id: employee for employee in employees}
|
||||||
result['employee'] = employee_data
|
|
||||||
|
for result in results:
|
||||||
|
if result['answer__answer'] in answers_employee:
|
||||||
|
employee_data = employee_dict.get(int(result['answer__answer']))
|
||||||
|
result['employee'] = employee_data
|
||||||
|
|
||||||
serialized_results = VoteResultSerializer(results, many=True).data
|
serialized_results = VoteResultSerializer(results, many=True).data
|
||||||
|
|
||||||
@@ -151,6 +156,7 @@ class GetResults(APIView):
|
|||||||
|
|
||||||
from rest_framework.views import exception_handler
|
from rest_framework.views import exception_handler
|
||||||
class VoteResultCreate(APIView):
|
class VoteResultCreate(APIView):
|
||||||
|
|
||||||
def post(self, request):
|
def post(self, request):
|
||||||
|
|
||||||
# print(request.data)
|
# print(request.data)
|
||||||
|
|||||||
Reference in new issue
Block a user