def game2_game(request): parsed = ViewHelper.parse_request_path(request, navigation()) module = ViewHelper.load_module(request, parsed['currentStep'], Module) game_questions = Module.get_game2_questions() if request.method == 'POST': answers = {} for i in range(len(game_questions)): index = str(i) ans = request.POST.get('answer[' + index + ']') title = game_questions[i]['title'] # Store their answers answers[title] = ans module.answers2 = json.dumps(answers) module.save() return redirect(parsed['nextUrl']) else: ViewHelper.clear_game_answers(module) context = { 'biases': Module.get_biases(), 'display_mode': 'game2', 'questions': game_questions, } return render_page(request, module, parsed, context)
def game(request): parsed = ViewHelper.parse_request_path(request, navigation()) module = ViewHelper.load_module(request, parsed['currentStep'], Module) # Add title to each question game_questions = Module.get_game_questions() for title in game_questions.keys(): game_questions[title]['title'] = title if request.method == 'POST': answers = {} if module.answers: answers = load_json(module.answers) for i in range(0, len(game_questions.values())): index = str(i) question_i = game_questions.values()[i] attr_i = request.POST.get('answer[' + index + ']') answers[question_i['title']] = attr_i module.answers = json.dumps(answers) module.biases = json.dumps(calculate_biases(game_questions, answers)) module.save() #print("Redirecting to: " + parsed['nextUrl']) # TODO: figure out why we cannot calculate the nextUrl return redirect(reverse('backpocket_explain')) #return redirect(parsed['nextUrl']) else: ViewHelper.clear_game_answers(module) context = { 'num_questions': len(game_questions), 'questions': game_questions.values(), } return render_page(request, module, parsed, context)
def bias_yesno(request, parsed, module, game_questions): for title in game_questions.keys(): game_questions[title]['title'] = title if request.method == 'POST': answers = {} if module.answers: answers = load_json(module.answers) for i in range(0, len(game_questions.values())): index = str(i) question_i = game_questions.values()[i] attr_i = request.POST.get('answer[' + index + ']') answers[question_i['title']] = attr_i module.answers = json.dumps(answers) module.biases = json.dumps(calculate_biases(game_questions, answers)) module.save() return redirect(parsed['nextUrl']) else: ViewHelper.clear_game_answers(module) context = { 'num_questions': len(game_questions), 'questions': game_questions.values(), } return render_page(request, module, parsed, context)