Skip to content

Commit

Permalink
Build skelleton of form handling code
Browse files Browse the repository at this point in the history
  • Loading branch information
ejs committed Sep 21, 2010
1 parent 5c520c6 commit 0568bdf
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
1 change: 0 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Recieve and check questions
Feedback results
Summery sheet

Expand Down
9 changes: 9 additions & 0 deletions lib/quizz_master.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 14 additions & 2 deletions maths_test.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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')
Expand Down
2 changes: 2 additions & 0 deletions views/questions.gen
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
$q.question

<select py:when="'single_choice'" name="${q.category+':'+q.guid}">
<option value="_"></option>
<option py:for="i in q.answer_data" value="$i">$i</option>
</select>

Expand All @@ -22,6 +23,7 @@
</ul>
<input type="hidden" value="quizz.quizzid"/>
<input type="submit" />
<input type="reset" />
</form>
</body>
</html>

0 comments on commit 0568bdf

Please sign in to comment.