def create(self, request, thread_pk): thread = self.get_thread_for_update(request, thread_pk) allow_start_poll(request.user, thread) try: if thread.poll and thread.poll.pk: raise PermissionDenied( _("There's already a poll in this thread.")) except Poll.DoesNotExist: pass instance = Poll( thread=thread, category=thread.category, poster=request.user, poster_name=request.user.username, poster_slug=request.user.slug, poster_ip=request.user_ip, ) serializer = NewPollSerializer(instance, data=request.data) if serializer.is_valid(): serializer.save() add_acl(request.user, instance) for choice in instance.choices: choice['selected'] = False thread.has_poll = True thread.save() return Response(PollSerializer(instance).data) else: return Response(serializer.errors, status=400)
def create(self, request, thread_pk): thread = self.get_thread(request, thread_pk) allow_start_poll(request.user, thread) try: if thread.poll and thread.poll.pk: raise PermissionDenied(_("There's already a poll in this thread.")) except Poll.DoesNotExist: pass instance = Poll( thread=thread, category=thread.category, poster=request.user, poster_name=request.user.username, poster_slug=request.user.slug, poster_ip=request.user_ip, ) serializer = NewPollSerializer(instance, data=request.data) if serializer.is_valid(): serializer.save() add_acl(request.user, instance) for choice in instance.choices: choice['selected'] = False thread.has_poll = True thread.save() return Response(PollSerializer(instance).data) else: return Response(serializer.errors, status=400)