def test(request, post_id): p = get_object_or_404(Post, pk=post_id) originalL = p.text lyrics = parse_lyrics(originalL) #remove empty words length = len(lyrics) blanks = random.sample(xrange(0, length), int(length/8)) for x in blanks: lyrics[x] = '-' return render(request, 'lyrify/test.html', {'lyrics': lyrics, 'index': blanks, 'post_id': post_id})
def check_answer(request): raw_index = request.POST["index"] post_id = request.POST["post_id"] index = [int(y) for y in str(raw_index)[1:-1].split(",")]; #convert unicode list to int list p = get_object_or_404(Post, pk=post_id) originalL = p.text lyrics = parse_lyrics(originalL) answers= [] total = 0 for i in index: answer = request.POST[str(i)] answers.append((i, answer)) if (answer == lyrics[i]): total += 1 return render(request, 'lyrify/results.html', {'lyrics': lyrics, 'answers': answers, 'total': total})