вывод всех голосований

This commit is contained in:
Cja committed 2025-01-14 09:57:47 +03:00
1 parent a4634b1d81
commit bbc74eb4bd
1 file changed
+10 -2
+10 -2
View File
@@ -15,20 +15,28 @@ class GetVotes(APIView):
def get(self, request):
user = request.user
print(type(user))
# user = DictEmployee.objects.get(login='9966-00-125')
# user = User.objects.get(username='9966-00-125')
now = datetime.now()
status = request.query_params.get('status')
votes = self.get_votes_by_status(status, now)
serialized_votes = VoteSerializer(votes, many=True).data
questions = Question.objects.filter(vote__in=votes)
files = [question.file.url for question in questions if question.file]
for vote in serialized_votes:
vote['is_passed'] = self.has_participated(user, vote['id'])
result = {
'votes': serialized_votes,
'files': files}
return Response(serialized_votes)
return Response(result)
def get_votes_by_status(self, status, now):
print(status)
if status is None:
return Vote.objects.all().order_by('dateend')
status_filters = {
'active': Vote.objects.filter(dateend__gt=now),
'completed': Vote.objects.filter(dateend__lt=now),