P-117
This commit is contained in:
1 parent
d8ed8e78b7
commit
ff0c5f09d2
3 files changed
+25
-15
No files matched your search
+13
-13
@@ -108,6 +108,10 @@ class VoteCreate(APIView):
|
||||
author=user,
|
||||
)
|
||||
|
||||
employees = DictEmployee.objects.filter(deleted=0)
|
||||
users = User.objects.filter(user__in=employees)
|
||||
Participant.objects.bulk_create([Participant(user=user, vote=vote) for user in users])
|
||||
|
||||
questions_files = {file.name: file for file in request.FILES.getlist('questionsfiles')}
|
||||
answers_files = {file.name: file for file in request.FILES.getlist('answersfiles')}
|
||||
|
||||
@@ -200,17 +204,13 @@ from rest_framework.views import exception_handler
|
||||
class VoteResultCreate(APIView):
|
||||
|
||||
def post(self, request):
|
||||
|
||||
# print(request.data)
|
||||
results = []
|
||||
user_id = request.user.id
|
||||
for item in request.data:
|
||||
item['user'] = user_id
|
||||
serializer = ResultSerializer(data=item)
|
||||
|
||||
if serializer.is_valid(raise_exception=True):
|
||||
serializer.save()
|
||||
results.append(serializer.data)
|
||||
|
||||
return Response(results)
|
||||
# return exception_handler(exc, context)
|
||||
answer_ids = [item['answer'] for item in request.data]
|
||||
answers = Answer.objects.in_bulk(answer_ids)
|
||||
vote = list(answers.values())[0].question.vote
|
||||
results = Result.objects.bulk_create(
|
||||
[Result(answer=answers[answer_id], user_id=user_id) for answer_id in answer_ids]
|
||||
)
|
||||
Participant.objects.filter(user=user_id, vote=vote).update(voted=True)
|
||||
serializer = ResultSerializer(results, many=True)
|
||||
return Response(serializer.data)
|
||||
Reference in new issue
Block a user