From 0568bdf86b086dd0af8ba0e7e19fb34eea896a82 Mon Sep 17 00:00:00 2001 From: Edward Saxton Date: Tue, 21 Sep 2010 16:04:56 +0100 Subject: [PATCH] Build skelleton of form handling code --- TODO | 1 - lib/quizz_master.py | 9 +++++++++ maths_test.py | 16 ++++++++++++++-- views/questions.gen | 2 ++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/TODO b/TODO index daff7a8..61ca3ec 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,3 @@ -Recieve and check questions Feedback results Summery sheet diff --git a/lib/quizz_master.py b/lib/quizz_master.py index 58bf998..b7971cc 100644 --- a/lib/quizz_master.py +++ b/lib/quizz_master.py @@ -6,3 +6,12 @@ class Quizz(object): def __init__(self, quizzid): self.quizzid = quizzid self.questions = dict((c, list(generate_questions(c, 5))) for c in categories) + + def answers(self, data): + for category in self.questions: + for question in self.questions[category]: + name = category + ':' + question.guid + question.answer(data.get(name), data.get('working:'+name)) + + def all_answered(self): + return True diff --git a/maths_test.py b/maths_test.py index f3b6ecf..7174708 100644 --- a/maths_test.py +++ b/maths_test.py @@ -1,5 +1,5 @@ import bottle -from bottle import Bottle, run, redirect +from bottle import Bottle, run, redirect, request from genshi.template import TemplateLoader from model.questions import QuestionStore @@ -19,7 +19,19 @@ def hello(): @myapp.post('/maths') def hello(): - return redirect('/results') + data = request.forms + if "quizz.quizzid" in request: + quizz = data_store.load_quizz(data.get('quizz.quizzid')) + quizz.answers(data) + + if quizz.all_answered(): + data_store.save_quizz(quizz) + return redirect('/results') + else: + # return questions with answers and working pre-filled + return redirect('/maths') + else: + return redirect('/maths') @myapp.route('/results') diff --git a/views/questions.gen b/views/questions.gen index c8852c4..815310e 100644 --- a/views/questions.gen +++ b/views/questions.gen @@ -12,6 +12,7 @@ $q.question @@ -22,6 +23,7 @@ +