예제 #1
0
 def test_topic_poll_post_vote_handler(self):
     """
     topic_poll_post_vote_handler signal
     """
     topic_poll_post_vote.send(sender=self.poll.__class__, poll=self.poll, user=self.user)
     self.assertEqual(TopicPollChoice.objects.get(pk=self.poll_choice.pk).vote_count, 1)
     self.assertEqual(TopicPollChoice.objects.get(pk=self.poll_other_choice.pk).vote_count, 0)
예제 #2
0
 def test_topic_poll_post_vote_handler(self):
     """
     topic_poll_post_vote_handler signal
     """
     topic_poll_post_vote.send(sender=self.poll.__class__, poll=self.poll, user=self.user)
     self.assertEqual(TopicPollChoice.objects.get(pk=self.poll_choice.pk).vote_count, 1)
     self.assertEqual(TopicPollChoice.objects.get(pk=self.poll_other_choice.pk).vote_count, 0)
예제 #3
0
def poll_vote(request, pk):
    # TODO: check if user has access to this topic/poll
    poll = get_object_or_404(TopicPoll, pk=pk)

    if not request.user.is_authenticated():
        return redirect_to_login(next=poll.get_absolute_url(),
                                 login_url=settings.LOGIN_URL)

    form = TopicPollVoteManyForm(user=request.user, poll=poll, data=request.POST)

    if form.is_valid():
        topic_poll_pre_vote.send(sender=poll.__class__, poll=poll, user=request.user)
        form.save_m2m()
        topic_poll_post_vote.send(sender=poll.__class__, poll=poll, user=request.user)
        return redirect(request.POST.get('next', poll.get_absolute_url()))

    messages.error(request, utils.render_form_errors(form))
    return redirect(request.POST.get('next', poll.get_absolute_url()))
예제 #4
0
def poll_vote(request, pk):
    # TODO: check if user has access to this topic/poll
    poll = get_object_or_404(TopicPoll, pk=pk)

    if not request.user.is_authenticated():
        return redirect_to_login(next=poll.get_absolute_url(),
                                 login_url=settings.LOGIN_URL)

    form = TopicPollVoteManyForm(user=request.user, poll=poll, data=request.POST)

    if form.is_valid():
        topic_poll_pre_vote.send(sender=poll.__class__, poll=poll, user=request.user)
        form.save_m2m()
        topic_poll_post_vote.send(sender=poll.__class__, poll=poll, user=request.user)
        return redirect(request.POST.get('next', poll.get_absolute_url()))
    else:
        messages.error(request, utils.render_form_errors(form))
        return redirect(request.POST.get('next', poll.get_absolute_url()))