Commit a54bd1fdff3868b7bd86f8f547f10e1849b80604
1 parent
2290803d
Exists in
master
and in
1 other branch
- corrected bugs in demo/ files.
- textarea, text and text_regex now remember last answer on practice mode.
Showing
5 changed files
with
33 additions
and
23 deletions
Show diff stats
demo/questions.yaml
| 1 | - | 1 | - |
| 2 | - ref: solar-system-mars | 2 | + ref: solar-system-jupiter |
| 3 | type: radio | 3 | type: radio |
| 4 | - text: Choose the correct answer | 4 | + text: Which one is the largest planet? |
| 5 | options: | 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 | correct: 0 | 10 | correct: 0 |
| 11 | shuffle: True | 11 | shuffle: True |
| 12 | discount: True | 12 | discount: True |
| 13 | hint: Just don't choose the wrong ones | 13 | hint: Just don't choose the wrong ones |
| 14 | # --------------------------------------------------------------------------- | 14 | # --------------------------------------------------------------------------- |
| 15 | - | 15 | - |
| 16 | - ref: solar-system-jupiter | 16 | + ref: solar-system-mars |
| 17 | type: checkbox | 17 | type: checkbox |
| 18 | text: Which ones are correct? | 18 | text: Which ones are correct? |
| 19 | options: | 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 | correct: [1, -1, 1, 0.5] | 24 | correct: [1, -1, 1, 0.5] |
| 25 | + # optional | ||
| 26 | + discount: True | ||
| 25 | hint: There are three. | 27 | hint: There are three. |
| 26 | # --------------------------------------------------------------------------- | 28 | # --------------------------------------------------------------------------- |
| 27 | - | 29 | - |
| 28 | - ref: solar-system-venus | 30 | + ref: question-v1 |
| 29 | type: text | 31 | type: text |
| 30 | text: What's your favorite basic color? | 32 | text: What's your favorite basic color? |
| 31 | correct: ['blue', 'green'] | 33 | correct: ['blue', 'green'] |
| 32 | hint: It's not red. | 34 | hint: It's not red. |
| 33 | # --------------------------------------------------------------------------- | 35 | # --------------------------------------------------------------------------- |
| 34 | - | 36 | - |
| 35 | - ref: question-v1 | 37 | + ref: question-v2 |
| 36 | type: text_regex | 38 | type: text_regex |
| 37 | - text: What's your favorite basic color? | 39 | + text: What's my favorite basic color? |
| 38 | correct: '[bB]lue' | 40 | correct: '[bB]lue' |
| 39 | hint: It's not red. | 41 | hint: It's not red. |
| 40 | # --------------------------------------------------------------------------- | 42 | # --------------------------------------------------------------------------- |
| 41 | - | 43 | - |
| 42 | - ref: question-v2 | 44 | + ref: question-colors |
| 43 | type: textarea | 45 | type: textarea |
| 44 | text: Write names of the three basic colors. | 46 | text: Write names of the three basic colors. |
| 45 | correct: demo/correct-question.py | 47 | correct: demo/correct-question.py |
| 46 | hint: They start by RGB and order does not matter. | 48 | hint: They start by RGB and order does not matter. |
| 47 | # --------------------------------------------------------------------------- | 49 | # --------------------------------------------------------------------------- |
| 48 | - | 50 | - |
| 49 | - ref: question-v3 | 51 | + ref: question-whatever |
| 50 | type: generator | 52 | type: generator |
| 51 | script: demo/generate-question.py | 53 | script: demo/generate-question.py |
| 52 | # the script should print a question in yaml format like the ones above. | 54 | # the script should print a question in yaml format like the ones above. |
demo/test.yaml
| @@ -39,18 +39,24 @@ questions: | @@ -39,18 +39,24 @@ questions: | ||
| 39 | # choose 1 from the following 3 questions | 39 | # choose 1 from the following 3 questions |
| 40 | - solar-system-mars | 40 | - solar-system-mars |
| 41 | - solar-system-jupiter | 41 | - solar-system-jupiter |
| 42 | - - solar-system-venus | ||
| 43 | points: 0.5 | 42 | points: 0.5 |
| 44 | 43 | ||
| 45 | # second | 44 | # second |
| 46 | - ref: | 45 | - ref: |
| 47 | - question-v1 | 46 | - question-v1 |
| 48 | - question-v2 | 47 | - question-v2 |
| 49 | - - question-v3 | ||
| 50 | # points: 1.0 is the default, if not defined here. | 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 | - ref: one-question | 59 | - ref: one-question |
| 54 | 60 | ||
| 55 | - # fourth | 61 | + # 6. |
| 56 | - another-question | 62 | - another-question |
questions.py
| @@ -390,7 +390,7 @@ class QuestionTextArea(Question): | @@ -390,7 +390,7 @@ class QuestionTextArea(Question): | ||
| 390 | self['grade'] = float(value) | 390 | self['grade'] = float(value) |
| 391 | except (ValueError): | 391 | except (ValueError): |
| 392 | self['grade'] = 0.0 | 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 | return self['grade'] | 395 | return self['grade'] |
| 396 | 396 |
templates/test.html
| @@ -178,9 +178,9 @@ | @@ -178,9 +178,9 @@ | ||
| 178 | </div> | 178 | </div> |
| 179 | % endfor | 179 | % endfor |
| 180 | % elif q['type'] in ('text', 'text_regex'): | 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 | % elif q['type'] == 'textarea': | 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 | % endif | 184 | % endif |
| 185 | </fieldset> | 185 | </fieldset> |
| 186 | 186 |