Esempio n. 1
0
def results(request, poll_key):
    try:
        p = Poll.get_by_id(int(poll_key))
        c = Choice.query(Choice.poll == p.key)
    except:
        raise Http404
    return render_to_response('polls/results.html', {'poll': p, 'choices': c})
Esempio n. 2
0
def detail(request, poll_key):
    try:
        p = Poll.get_by_id(int(poll_key))
        c = Choice.query(Choice.poll == p.key)
    except:
        raise Http404
    return render_to_response('polls/detail.html',
                            {'poll': p, 'choices': c},
                            context_instance=RequestContext(request))
Esempio n. 3
0
def vote(request, poll_key):
    try:
        p = Poll.get_by_id(int(poll_key))
    except:
        raise Http404
    try:
        selected_choice = Choice.get_by_id(int(request.POST['choice']),
                                            parent=p.key)
        selected_choice.votes += 1
        selected_choice.put()
        return HttpResponseRedirect(reverse('polls.views.results', args=(p.key.id(),)))
    except:
        raise Http404