Commit a54bd1fdff3868b7bd86f8f547f10e1849b80604

Authored by Miguel Barao
1 parent 2290803d
Exists in master and in 1 other branch dev

- corrected bugs in demo/ files.

- textarea, text and text_regex now remember last answer on practice
  mode.
demo/correct-question.py 100644 → 100755
1 1 #!/usr/bin/env python3.4
2 2  
  3 +import re
3 4 import sys
  5 +
4 6 s = sys.stdin.read()
5 7  
6 8 # set of words converted to lowercase lowercase
... ...
demo/questions.yaml
1 1 -
2   - ref: solar-system-mars
  2 + ref: solar-system-jupiter
3 3 type: radio
4   - text: Choose the correct answer
  4 + text: Which one is the largest planet?
5 5 options:
6   - - This one is correct
7   - - Wrong
8   - - Very wrong!
9   - # optional
  6 + - Jupiter
  7 + - Mercury
  8 + - Mars
  9 + # optional, default is 0, True, True
10 10 correct: 0
11 11 shuffle: True
12 12 discount: True
13 13 hint: Just don't choose the wrong ones
14 14 # ---------------------------------------------------------------------------
15 15 -
16   - ref: solar-system-jupiter
  16 + ref: solar-system-mars
17 17 type: checkbox
18 18 text: Which ones are correct?
19 19 options:
20   - - Yes
21   - - No
22   - - Yes
23   - - Obvious one, not very important
  20 + - $1 > 0$
  21 + - $-1 > 1$
  22 + - $\sqrt{3} > \sqrt{2}$
  23 + - $0 = 0$
24 24 correct: [1, -1, 1, 0.5]
  25 + # optional
  26 + discount: True
25 27 hint: There are three.
26 28 # ---------------------------------------------------------------------------
27 29 -
28   - ref: solar-system-venus
  30 + ref: question-v1
29 31 type: text
30 32 text: What's your favorite basic color?
31 33 correct: ['blue', 'green']
32 34 hint: It's not red.
33 35 # ---------------------------------------------------------------------------
34 36 -
35   - ref: question-v1
  37 + ref: question-v2
36 38 type: text_regex
37   - text: What's your favorite basic color?
  39 + text: What's my favorite basic color?
38 40 correct: '[bB]lue'
39 41 hint: It's not red.
40 42 # ---------------------------------------------------------------------------
41 43 -
42   - ref: question-v2
  44 + ref: question-colors
43 45 type: textarea
44 46 text: Write names of the three basic colors.
45 47 correct: demo/correct-question.py
46 48 hint: They start by RGB and order does not matter.
47 49 # ---------------------------------------------------------------------------
48 50 -
49   - ref: question-v3
  51 + ref: question-whatever
50 52 type: generator
51 53 script: demo/generate-question.py
52 54 # the script should print a question in yaml format like the ones above.
... ...
demo/test.yaml
... ... @@ -39,18 +39,24 @@ questions:
39 39 # choose 1 from the following 3 questions
40 40 - solar-system-mars
41 41 - solar-system-jupiter
42   - - solar-system-venus
43 42 points: 0.5
44 43  
45 44 # second
46 45 - ref:
47 46 - question-v1
48 47 - question-v2
49   - - question-v3
50 48 # points: 1.0 is the default, if not defined here.
51 49  
52   - # third
  50 + # 3.
  51 + - ref:
  52 + - question-colors
  53 +
  54 + # 4.
  55 + - ref:
  56 + - question-whatever
  57 +
  58 + # 5.
53 59 - ref: one-question
54 60  
55   - # fourth
  61 + # 6.
56 62 - another-question
... ...
questions.py
... ... @@ -390,7 +390,7 @@ class QuestionTextArea(Question):
390 390 self['grade'] = float(value)
391 391 except (ValueError):
392 392 self['grade'] = 0.0
393   - raise Exception('Correction of question "%s" returned nonfloat.' % self['ref'])
  393 + raise Exception('Correction of question "{0}" returned nonfloat "{1}".'.format(self['ref'], value))
394 394  
395 395 return self['grade']
396 396  
... ...
templates/test.html
... ... @@ -178,9 +178,9 @@
178 178 </div>
179 179 % endfor
180 180 % elif q['type'] in ('text', 'text_regex'):
181   - <input type="text" name="${q['ref']}" class="form-control">
  181 + <input type="text" name="${q['ref']}" class="form-control" value="${q['answer'] if q['answer'] is not None else ''}">
182 182 % elif q['type'] == 'textarea':
183   - <textarea class="form-control" rows="8" name="${q['ref']}"></textarea>
  183 + <textarea class="form-control" rows="8" name="${q['ref']}">${q['answer'] if q['answer'] is not None else ''}</textarea>
184 184 % endif
185 185 </fieldset>
186 186  
... ...