Esempio n. 1
0
    def render(self, context):
        if not isinstance(context.get("request"), HttpRequest):
            raise template.VariableDoesNotExist(
                "Not found request object in template context."
                + "Please add `django.core.context_processors.request` to "
                + "TEMPLATE_CONTEXT_PROCESSORS tuple in settings.py"
            )

        poll = self.get_poll()
        if poll:
            poll.can_vote = can_vote(context["request"], poll)
            return self.allpoll_render(context, poll)
        return ""
Esempio n. 2
0
def poll_vote(request, poll_id):
    poll = get_object_or_404(Poll.objects.public(), id=poll_id)
    context = {'poll': poll}

    if request.method == 'POST':
        if not can_vote(request, poll):
            return HttpResponseForbidden()
        try:
            choice_id = int(request.POST.get('choice_id'))
        except TypeError, ValueError:
            raise Http404()

        choice = get_object_or_404(Choice, poll=poll, id=choice_id)
        choice.vote()

        if request.is_ajax():
            response = render(request, 'allpoll/block_result.html', context)
        else:
            response = redirect('.')
        mark_voted(request, response, poll)
Esempio n. 3
0
 def get_queryset(self):
     queryset = Poll.objects.public()
     for poll in queryset:
         poll.can_vote = can_vote(self.request, poll)
     return queryset
Esempio n. 4
0

def poll_vote(request, poll_id):
    poll = get_object_or_404(Poll.objects.public(), id=poll_id)
    context = {'poll': poll}

    if request.method == 'POST':
        if not can_vote(request, poll):
            return HttpResponseForbidden()
        try:
            choice_id = int(request.POST.get('choice_id'))
        except TypeError, ValueError:
            raise Http404()

        choice = get_object_or_404(Choice, poll=poll, id=choice_id)
        choice.vote()

        if request.is_ajax():
            response = render(request, 'allpoll/block_result.html', context)
        else:
            response = redirect('.')
        mark_voted(request, response, poll)
    else:
        if 'result' in request.GET or not can_vote(request, poll):
            template = 'allpoll/result.html'
        else:
            template = 'allpoll/vote.html'

        response = render(request, template, context)

    return response