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})
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))
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