コード例 #1
0
ファイル: tests_topic_poll.py プロジェクト: gone/Spirit
    def test_create_vote_single(self):
        """
        TopicPollVoteManyForm
        """
        TopicPollVote.objects.all().delete()

        form_data = {'choices': self.poll_choice.pk, }
        form = TopicPollVoteManyForm(user=self.user, poll=self.poll, data=form_data)
        self.assertTrue(form.is_valid())
        form.save_m2m()
        self.assertEqual(len(TopicPollVote.objects.filter(choice=self.poll_choice)), 1)
コード例 #2
0
ファイル: tests_topic_poll.py プロジェクト: gdyuldin/Spirit
    def test_create_vote_single(self):
        """
        TopicPollVoteManyForm
        """
        TopicPollVote.objects.all().delete()

        form_data = {"choices": self.poll_choice.pk}
        form = TopicPollVoteManyForm(user=self.user, poll=self.poll, data=form_data)
        self.assertTrue(form.is_valid())
        form.save_m2m()
        self.assertEqual(len(TopicPollVote.objects.filter(choice=self.poll_choice)), 1)
コード例 #3
0
    def test_update_vote_single(self):
        """
        TopicPollVoteManyForm
        """
        self.assertEqual(len(TopicPollVote.objects.filter(choice=self.poll_choice2)), 0)
        self.assertEqual(len(TopicPollVote.objects.filter(choice=self.poll_choice)), 2)

        form_data = {'choices': self.poll_choice2.pk, }
        form = TopicPollVoteManyForm(user=self.user, poll=self.poll, data=form_data)
        self.assertTrue(form.is_valid())
        form.save_m2m()
        self.assertEqual(len(TopicPollVote.objects.filter(choice=self.poll_choice2)), 1)
        self.assertEqual(len(TopicPollVote.objects.filter(choice=self.poll_choice)), 1)
コード例 #4
0
ファイル: topic_poll.py プロジェクト: IronLemon/Spirit
def poll_vote(request, pk):
    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():
        form.save_m2m()
        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()))
コード例 #5
0
ファイル: topic_poll.py プロジェクト: yanabeda/Spirit
def poll_vote(request, pk):
    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():
        form.save_m2m()
        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()))
コード例 #6
0
ファイル: topic_poll.py プロジェクト: gdyuldin/Spirit
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()))
コード例 #7
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()))