Exemplo n.º 1
0
def questionnaire(request, contestant):
    characters = People.objects.filter(~Q(name='Nobody'))
    cont = get_object_or_404(Contestant, name=contestant)

    if request.method == 'POST':
        for person in characters:
            x = TestQuestion(request.POST, prefix=person)

            if x.is_valid():
                test = Result()
                test.name = cont
                test.character = person
                test.killed_by = x.cleaned_data['killed_by']
                test.is_survivor = x.cleaned_data['is_survivor']
                test.save()
                print person

        return HttpResponseRedirect('/done')
    else:
        forms = {}
        for person in characters:
            x = TestQuestion(initial={'character':person, 'name':cont}, prefix=person)
            forms[person] = x


    return render_to_response('brbappl/questions.html', 
        {'forms': forms}, 
        context_instance=RequestContext(request)
    )